Exceptions can be caught when a programmer expects them. This allows the program to continue if the exception is minor or at least exit gracefully.
Java[]
try{ obj.riskyfunction(); }catch(Exception ex){ System.out.println("an exception has occurred"); }
a try-catch block can have multiple catch statements to deal with different types of Exception.
See Also[]
![]() |