java - How can I get the name of the class that throws a custom made Exception -
i'm preparing project college need write custom made exception thrown couple of classes in same package when not initialized properly. problem must let user know of classes wasn't initialized (and throwed exception)... thinking this:
class initializationexception extends exception { private static final string default_msg = "this " + classname-throwingme + " had not been initialized properly!"; protected string msg; initializationexception() { this.msg = default_msg; } initializationexception(string msg) { this.msg = msg; } }
(btw, can achieved via reflection?)
look @ throwable.getstacktrace()
. each stacktraceelement
has getclassname()
. can @ element [0]
determine origination of exception.
Comments
Post a Comment