what?
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Exception e = new Exception( String ) -- constructor
catch ( Exception e ){}
You just created an instance of the Exception and named it 'e'.
getMessage() is a method of Throwable, the superclass of Exception. So you are calling the method on the instantiated Exception object, e, which prints the String you put in the constructor.
yes, it gets it's message from a "throws" declaration somewhere below the "try/catch" block.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
what?
what?
Originally posted by Michael Matola:
Marilyn,
I put your code inside a class to play with it, but it won't compile. The compiler doesn't like that there are two e's in the same scope:
C:\Michael\javaranch\projects\stuff\Except.java:19: e is already defined in test(java.lang.String)
catch ( Exception e )
^
1 error
Tool completed with exit code 1
I don't understand why you're instantiating an Exception at the top of the method. All the exceptions that you have catch blocks for here are being thrown by the JVM, right?
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|