asked in Java by (8.9k points)
0 like 0 dislike
26 views

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

java get exception message

1 Answer

0 like 0 dislike
answered by (8.9k 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);
}

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.

Related questions

0 like 0 dislike
1 answer 37 views
0 like 0 dislike
1 answer 20 views
0 like 0 dislike
1 answer 16 views
0 like 0 dislike
1 answer 10 views
0 like 0 dislike
1 answer 21 views
0 like 0 dislike
1 answer 38 views
0 like 0 dislike
1 answer 53 views
0 like 0 dislike
1 answer 42 views
0 like 0 dislike
1 answer 63 views
...