• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why do we need different exception classes in Java?  RSS feed

 
Guru MaheswaraReddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have one main exception class called "Exception". Also java provides different exceptions like FileNotFoundException,IllegalArgumentException ......
We can handle exception by catching "Exception" class. What is the advantage of having more number of child exception classes.
In my project if i want follow some best exception handling methods, When to create my own exception?


Thanks,
Guru
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good article to read...

http://onjava.com/onjava/2003/11/19/exceptions.html

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you might want to handle different exceptions differently.

Application-specific exceptions are useful when you're trying to abstract underlying errors and/or when using some form of declarative exception handling.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!