• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use User Defined Exception  RSS feed

 
Bhavesh Sangwan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my method which raising an exception and I want to catch this exception using my own class... method is...

And my user defined exceptions class is...


And calling method is...


Please guide me HOW to use that MyException class ...
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhavesh Sangwan wrote:my method which raising an exception

No it isn't, because you've already caught it.

and I want to catch this exception using my own class... method is...

Then don't use try...catch (at least, not like that). You've commented out the code that actually throws your exception, so if you run it with a divisor of 0, you'll get an ArithmeticException.

Winston
 
vinay chaturvedi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to define the div method as below :



User defined Exception is always thrown using "throw" keyword.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you been through the Java Tutorials?
 
Bhavesh Sangwan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vinay! Your information is very helpful for me..... The key point was throw keyword...as I was trying to catch the exception using userdefined class.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!