Post a Job  |   Ask a Question?   |   Already registered? login or register
MD Rahman
27/01/2016 05:38 PM

Custom Exception


While creating custom exception we generally extends from Exception class or Throwable class. I just have the query how these affects differently in my own exception
Spam    2 Comments

samir,panda
27/01/2016 23:26:07
@Rahman Throwable is the Parent for both Exception and Error,... so if you extends from Throwable then you can address both Exception as well as the Errror.. But if you extends from Exception then you can address the Sub-class of Exception only... But as i know if you want yr own coustm Exception then better to make it Un-Checked exception...so u can achive it by extending from RuntimeException..

Basanta,Hota
28/01/2016 02:52:21
Simple MD, ok for understanding Just take one example Suppose I throw one custom Exception which is InavalidTransactionException(); As you know every custom Exception is also a class so just see below class InavalidTransactionException extends Exception { InavalidTransactionException(){ Super (); } } See if this custom Exception is also a class then at compilation time compiler add defult constructor and call super parenthesis. Which is call the constructor of ur Supper class means from which class u Extends ur class. . And it is checked exception if ur custom Exception class extends from Exception so u should have to declare throws in method level That's why when caller call ur method in which u throw Exception then it report to method caller. ...

Languages :
xml