0 like 0 dislike
8 views
asked in Java by (4.7k points)

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

java get exception message

Your answer

pre, code

Preview

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 (4.7k 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 11 views
0 like 0 dislike
1 answer 5 views
0 like 0 dislike
1 answer 12 views
0 like 0 dislike
1 answer 26 views
0 like 0 dislike
1 answer 24 views
0 like 0 dislike
1 answer 24 views
0 like 0 dislike
1 answer 23 views
0 like 0 dislike
1 answer 29 views
0 like 0 dislike
1 answer 25 views
0 like 0 dislike
1 answer 5 views
...