public class BasicTryCatch { public static void main(String[] args) { int[] array = new int[3]; try { array[4] = 1; // outside its boundry } catch (Exception e) { System.out.println("Exception thrown: " + e.toString()); } } }
# java BasicTryCatch Exception thrown: java.lang.ArrayIndexOutOfBoundsException: 4
Basic Try Catch
Basic Try Catch Finally
Catch Multiple Exceptions At Once
Chained Exceptions
Create Your Own Exception Class
Example Of A NullPointerException
Exception Matching
Get A Stack Trace Of An Exception
Handling Multiple Catch Clauses
Print Stack Trace
Propagating an Exception
Rethrowing Exceptions
Shutdown Hook
Throw an Exception
Try Block Where Finally Clause Does Not Run
Try Block Without Catch
Try With Resources Statement