Weird output of Throwable getMessage()
- by Ravi Gupta
Hi I have below pseudo code with throws an exception like this
throw new MyException("Bad thing happened","com.stuff.errorCode");
where MyException extends Exception class. So the problem is when I try to get the message from MyException class by calling myEx.getMessage() it returns
???en_US.Bad thing happened???
instead of my original message i.e. Bad thing happened
I have checked that MyException class doesn't overrides Throwable class's getMessage() behavior.
Below is the how the call passes from MyException.getMessage() to Throwable.getMessage()
public MyException(String msg, String sErrorCode){
super(msg);
this.sErrorCode = sErrorCode;
this.iSeverity = 0;
}
which then calls
public Exception(String message) {
super(message);
}
and finally
public Throwable(String message) {
fillInStackTrace();
detailMessage = message;
}
when I do a getMessage on myexception it calls Throwable's getMessage as below
public String getMessage() {
return detailMessage;
}
So ideally it should return the original message as I set when throwing the exception. What's the ???en_US thing ?