e.printStackTrace displays a message on the console, you can use this when the user sees the console ...
e.getMessage () returns a string, so you can handle it as you like, for example:
try { } catch (IOException E) { System.out.println("Error occured. Please try again."+ e.getMessage()); }
or use getMessage () when you don’t have a console, but, for example, a GUI, you can set:
textField.setText(e.getMessage());
source share