0 like 0 dislike
10 views
asked in Java by (5.6k points)

How I can to get an exception message in a string variable in Java programmig language?

java get exception message

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

0 like 0 dislike
answered by (5.6k points)

Use getMessage() method of exeption type variable.

String errorMessage = null;
try {
	throw(new Exception("Let's throw some exception message here"));
} catch(Exception e) {
	System.out.println("In Exception block.");
	errorMessage = e.getMessage();
} finally {
	System.out.println(errorMessage);
}

Related questions

0 like 0 dislike
1 answer 20 views
0 like 0 dislike
1 answer 7 views
0 like 0 dislike
1 answer 20 views
0 like 0 dislike
1 answer 34 views
0 like 0 dislike
1 answer 30 views
0 like 0 dislike
1 answer 35 views
0 like 0 dislike
1 answer 46 views
0 like 0 dislike
1 answer 42 views
0 like 0 dislike
1 answer 29 views
0 like 0 dislike
1 answer 13 views
...