Created
August 6, 2020 06:31
-
-
Save LaurentiuGabriel/5f61d95f1a230e1407ad500c93283354 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File; | |
| import java.io.FileNotFoundException; | |
| import java.io.FileReader; | |
| public class App { | |
| public static void main(String[] args) { | |
| //Example of checked exception | |
| File file = new File("C:\\randomname.txt"); | |
| try { | |
| FileReader fileReader = new FileReader(file); | |
| } catch (FileNotFoundException e) { | |
| e.printStackTrace(); | |
| } | |
| //Example of runtime exception | |
| Integer[] arr = {2,3,4}; | |
| try { | |
| System.out.println(arr[2]); | |
| System.out.println("Line after exception"); | |
| } catch (Exception e) { | |
| System.out.println("Exception caught"); | |
| } | |
| finally { | |
| System.out.println("Finally block"); | |
| } | |
| System.out.println("Additional Line"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment