February 2018

Checked and Unchecked Exceptions in Java

  • Satish 

1. Overview Java Exceptions fall into two main categories: checked exceptions and unchecked exceptions. In this article, we’ll provide some code samples on how to use them. 2. Checked Exceptions In general, checked exceptions represent errors outside the control of the program. For example, the constructor of FileInputStream throws FileNotFoundException if the input file does not exist. Java verifies checked exceptions at compile-time. Therefore, we should use the throws keyword to declare a checked exception: private static void checkedExceptionWithThrows() throws FileNotFoundException { File file = new File(“not_existing_file.txt”);… Read More »Checked and Unchecked Exceptions in Java