If you want to print a message (or execute some code), if the exception is not thrown at a specific point, then put this code after the line that may cause the exception:
try { Socket s = new Socket(IPaddress,px); System.out.print("Service discovered at port: " + px + "\n"); } catch(Exception e) { System.out.print("Nothing\n"); }
This causes print fail if an exception is thrown, since the try will be aborted.
Alternatively, you can have a continue statement inside catch :
try { Socket s = new Socket(IPaddress,px); } catch(Exception e) { System.out.print("Nothing\n"); continue; } System.out.print("Service discovered at port: " + px + "\n");
This calls all the code after try / catch fails if an exception is thrown, since the loop explicitly tells you to go to the next iteration.
templatetypedef
source share