Exceptions

An exception is an object that’s created when an error occurs in a Java program, and Java can’t automatically fix the error. The exception object contains information about the type of error that occurred. The most important information — the cause of the error — is indicated by the name of the exception class used to create the exception. You usually don’t have to do anything with an exception object other than figure out which one you have.

A different exception class represents each type of exception that can occur. Here are some typical exceptions:

check.png IllegalArgumentException : You passed an incorrect argument to a method.

check.png InputMismatchException : The console input doesn’t match the data type expected by a method of the Scanner class.

check.png ArithmeticException : You tried an illegal type of arithmetic operation, such as dividing an integer by 0 (zero).

check.png IOException : A method that performs I/O (such as reading or writing a file) encountered an unrecoverable I/O error.

check.png ClassNotFoundException ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.