• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception not getting called  RSS feed

 
Sani Abacha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this custom exception



and then in my code I have



I expect to see

################# MyException invoked ###########



but instead i am seeing

################# Exception invoked ###########

why is this so even though MyException extends ArithmeticException , the catch segment is not being called
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int u=j/0; still throws ArithmeticException. creamMe() declares that it will throw MyException or an exception higher up the tree. And it does. It throws ArithmeticException.

You'd need to explicitly throw MyException somewhere to have it caught by the catch block.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sani Abacha wrote:
I expect to see

################# MyException invoked ###########



but instead i am seeing

################# Exception invoked ###########

why is this so even though MyException extends ArithmeticException , the catch segment is not being called



Ahhh... if you want a specific exception instantiated and thrown, don't you actually need to instantiate the exception and throw it?

Henry
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!