• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exceptions  RSS feed

 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code:

I wonder how it works. Let me try an explanation:

1) First it calls the method hello() which calls the method foo().
2) The method foo() throws an exception of the type MyException.
3) MyException extends Exception.
4) public MyException(String msg) is a constructor with an argument which calls with this argument the constructor public Exception(String message).
5) catch(MyException me) comes into play.
6) System.out.pringln(me) prints: exceptions.MyException: Exception from foo.

Till 4) I am sure. But I am not sure what really happens after public Exception(String message) has been called. I would kindly ask someone for a clarification.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what really happens after public Exception(String message) has been called.

What line is that statement on? I don't see that code in what is posted.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 19 creates an instance of MyException which is just like any object. It doesn't do anything special. If you discard it, no exception will be thrown. It's the throws that starts the "magic" of exception handling.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!