Professional Documents
Culture Documents
4 2 4 P 603a0f36427fc File
4 2 4 P 603a0f36427fc File
4 2 4 P 603a0f36427fc File
Written by
Sushama Pawar
Lecturer, Department of Information Technology[NBA Accredited],Vidyalankar Polytechnic,
Mumbai
Unit Outcome 2 :
Develop program for handling the
given exception.
Written by
Sushama Pawar
Lecturer, Department of Information Technology[NBA Accredited],Vidyalankar Polytechnic,
Mumbai
Learning Outcome 2d : Students
should able to create own exception
and understand the concept of
exception in subclass.
Written by
Sushama Pawar
Lecturer, Department of Information Technology[NBA Accredited],Vidyalankar Polytechnic,
Mumbai
What we will learn today
Sushama Pawar
Lecturer, Department of Information Technology[NBA Accredited],Vidyalankar Polytechnic,
Mumbai
Creating own
exception
Exception in
subclass
Java provides us facility to create our own exceptions which are basically derived classes of Exception.
Sometimes, the built-in exceptions in Java are not able to describe a certain situation. In such cases, a
user can also create exceptions which are called ‘User-Defined Exceptions’.
User Defined Exception or custom exception is creating your own exception class and throws that
exception using ‘throw’ keyword. This can be done by extending the class Exception.
Key points
A user-defined exception must extend Exception class.
When Exception handling is involved with Method overriding, ambiguity occurs. The compiler gets
confused as which definition is to be followed. Such problems were of two types:
► If the superclass method does not declare an exception
► If the superclass method does not declare an exception, subclass overridden method cannot declare the
checked exception but it can declare unchecked exception.
► If the superclass method declares an exception
► If the superclass method declares an exception, subclass overridden method can declare same, subclass
exception or no exception but cannot declare parent exception.
System.out.println("SubClass");
}