Skip to content
Advertisement

Tag: getmessage

How to properly use Exception method getMessage

I have the following java code: how can I set e.getMessage() so that System.out.println(e.getMessage()) will print “Pretty please enter an int: ” Answer You only set the message when the exception is created, it’s an argument to the constructor. In your case it would have been nice if the InputMismatchException was created like this: tnrow new InputMismatchException(“Pretty please enter an

Advertisement