How to show an error message in java in a friendly way -
I have a question because I'm making a start in Java, you can find it silly.
I am writing a method to read a file and when an error does not exist then just be visible.
file f = new file (FILE_path); If (f.exists () & amp; amp; amp; amp; amp;; LOGGER.error ("error message:" + e.getMessage ());}} and {LOGGER.error ("file does not exist Or it can not be read. ");} But it is revealed by a red error which also appears in addition to the error and then the program stops.
Exception in thread "main" Java Io.FileNotFoundException: / home / project / file_path (no such file or directory on java.io.FileInputStream.open) java.io.FileInputStream on. & Lt; Init> (FileInputStream.java146) Now my question is that Is this program not stable at this level and we only show friendly messages? Or can we not escape from that and this exception error always shows that we also try and catch?
You can always use joppenpen:
file f = new file (FILE_path ); If (f.exists () & amp; amp; amp; amp; amp; amp; amp; f.canRead ()) {try {// do something} hold (IOException e) {JOptionPane.showMessageDialog (tap, "something wrong Happened "," title ", JOptionPane.ERROR_ME SSAGE); LOGGER.error ("Error Message:" + e.getMessage ()); }} And {LOGGER.error ("File does not exist or can not be read."); }
Comments
Post a Comment