Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Exception_Handling
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package pakage;
class MarksOutOfBoundException extends Exception
{
MarksOutOfBoundException(String message)
{
super(message);
}
}
class student
{
String name;
int marks;
void setname (String name)
{
this.name=name;
}
public void setmarks(int marks)throws MarksOutOfBoundException
{
if(marks>100)
{
throw new MarksOutOfBoundException("Marks can't be greater than 100");
}
this.marks=marks;
}
String display()
{
return name;
}
int display1()
{
return marks;
}
}
public class q3{
public static void main (String []args)
{
student s=new student();

s.setname("Saket");
try
{

s.setmarks(90);
}
catch(MarksOutOfBoundException e)
{
System.out.println(e.getMessage());
}
System.out.println(s.display()+" has got "+s.display1()+" marks");

}
}