java - Does throwing an exception change its state? -
i've run simple experiments this:
public static void main(string[] args) { try { nullpointerexception n = new nullpointerexception(); system.out.println(lists.newarraylist(n.getstacktrace())); n.printstacktrace(); system.out.println(lists.newarraylist(n.getstacktrace())); throw n; } catch (nullpointerexception e) { e.printstacktrace(); system.out.println(lists.newarraylist(e.getstacktrace())); } }
and output this:
java.lang.nullpointerexception @ mytest.main(mytest.java:231) java.lang.nullpointerexception @ mytest.main(mytest.java:231) [mytest.main(abstractscannertest.java:231)] [mytest.main(abstractscannertest.java:231)] [mytest.main(abstractscannertest.java:231)]
but wonder if done exception when thrown. academic question, though relevant under circumstances if exception part of api , may or may not have been thrown when provided implementation.
no, throwable
object not modified throw
operation; passed call stack similar how method's argument be. throwable
s designed immutable objects , don't have setters, though support modifying stack trace rpc or similar frameworks can make sure appropriate error-tracing information included. said, throwable
object other, , write throwable
class had mutator methods called in catch
block, though that's not usual.
Comments
Post a Comment