- Three types of errors that occur in Java: Syntax Errors, Logic Errors, and Runtime Errors
 
- Syntax errors occur when code formatting rules defined by Java are violated. 
- The Java compiler reports syntax errors when an attempt is made to compile a program. 
- Logic errors occur when a syntactically correct program compiles and runs, but produces results that is incorrect. 
- Logic errors cause incorrect program flow. 
- Runtime errors occur when an unexpected error occurs while a program is running. 
- Runtime errors may be due to unexpected situations such as invalid array indexes, missing files, etc. These are called exceptions. 
- With no special intervention, an exception will cause a Java program to halt with an indication of what caused the exception. 
- Runtime exceptions may be caught and handled by a Java program. 
- The - try-catchand- try-catch-finallystatements are used to catch and handle runtime exceptions.
 
- Exceptions are represented as objects in the Java Core Library and all exception classes inherit the - java.lang.Exceptionclass.
 
- Common exception classes include - ArithmeticException,- NullPointerException,- IndexOutOfBoundsException,- ArrayIndexOutOfBoundsException,- IllegalArgumentException
 
- The try-block contains code which may throw an exception. 
- The catch-block is the code that will be executed if a matching exception is thrown. 
- The optional finally-block contains code that is guaranteed to execute, regardless of whether an exception was thrown. 
- The catch-block may specify the class or superclass that it is willing to catch and handle. A catch-block will handle a thrown exception object if it binds to the declared exception variable. 
- Multiple catch-blocks may be specified if different exception classes are to be handled differently. 
- As a class, exceptions may be instantiated to create exception objects and the object may be thrown. This is accomplished with the throw statement. 
- Exception classes may be subclasses to create new custom catchable exception classes with unique data and behavior. 
- There are two important exception class categories: checked exceptions and unchecked exceptions. 
- The Java compiler requires that all checked exceptions are handled with a try-catch and will refuse to compile a program with a checked exception that is not caught. 
- The Exception class and its derived classes, excluding the RuntimeException subclass and its derived classes, are checked exceptions. 
- Checked exceptions include IOExceptions and its subclasses such as FileNotFoundException. 
- The handling of checked exceptions may be deferred from one method to its calling method by adding a throws modifier to the method declaration. 
- Unchecked exceptions are not required to be caught, and may cause a program to halt and dump a stack trace at runtime if thrown and not caught. 
- RuntimeExceptions, such as IndexOutOfBoundException, are examples of unchecked exceptions. 
- There is an important distinction between errors and exceptions in Java: unlike exceptions, errors are fatal and cannot be handled. 
- Exception objects have their own methods that may be invoked when instantiated or caught. 
- The - printStackTrace()method of Exception objects will print to the terminal a snapshot of the call stack at the moment the exception was thrown.
 
- A variation on the try-catch statement called try-with-resources will automatically close an open resource when an exception occurs, such as an open file.