-1

When throw exception, I found that always included java.lang.exception or javax.ssl.xxxx and so on, I just want to get only messages but not including exception type, how can I do it?

As exception has many types, I can not just filter string start with, is it available to do so?

Andy Chan
  • 277
  • 5
  • 16

1 Answers1

0

Find below a small snippet as demonstration for my comment

try {
    int i = 1 / 0;
} catch (Exception e) {
    System.out.println("exception  = " + e);
    System.out.println("getMessage = " + e.getMessage());
}

output

exception  = java.lang.ArithmeticException: / by zero
getMessage = / by zero
SubOptimal
  • 22,518
  • 3
  • 53
  • 69