Tuesday 15 June 2010

JAVA exception getMessage() method calling constructor -



JAVA exception getMessage() method calling constructor -

public class testexception extends exception { public testexception() { super("test exception 1 thrown!"); system.out.println("test exception 2 thrown!"); } ... }

in place, have code this:

testexception exceptionobject = new testexception(); system.out.println(exceptionobject.getmessage());

i prints out result follows:

test exception 2 thrown! test exception 1 thrown!

could kindly tell me why output of println method come first?

first build exception (by calling new testexception()), sets message property of exception "test exception 1 thrown!", doesn't print it, , prints "test exception 2 thrown!".

then print value of getmessage(), calling system.out.println(exceptionobject.getmessage());. prints "test exception 1 thrown!"

hence output got.

btw, create clear, regardless of messages printed, no exception beingness thrown here.

java exception

No comments:

Post a Comment