Thursday, 8 March 2012

User defined exceptions

Creating Own Exceptions:

•We can create our own exceptions by creating a subclass of the class “Exception” which is a subclass of “Throwable”.
•There is no need to implement any methods, since our class already extends “Exception”, all the methods available in it are accessible in our class also.
•We must use “throw” for explicitly throwing our own created exception, also we must specify the exception in the “throws” clause too.
•Following methods are available/accessible in our class which extends the class “Exception”:



Advantages of Exception Handling: 

•Separating Error-Handling Code from "Regular" Code
•Propagating errors up the call stack
•Grouping and differentiating error types

No comments:

Post a Comment