October 2018
Intermediate to advanced
370 pages
9h 15m
English
In Java, all exceptions are divided into two groups:
If a class isn't a subtype of RuntimeException and it inherits the Exception class, then this class belongs to checked exceptions. If a function throws checked exceptions, then we have to wrap its invoking into the try { ... } catch { ... } finally { ... } block. The finally block can be omitted.
The following example contains the main function that creates a new instance of the FileInputStream class:
public class Example2 { public static void main(String[] args) { new FileInputStream("invalid/path"); }}
Since a constructor of FileInputStream throws FileNotFoundException, we can't compile this code. IntelliJ IDEA shows the following tip:
To fix this ...
Read now
Unlock full access