Skip to content

Instantly share code, notes, and snippets.

@LaurentiuGabriel
Created August 6, 2020 06:31
Show Gist options
  • Select an option

  • Save LaurentiuGabriel/5f61d95f1a230e1407ad500c93283354 to your computer and use it in GitHub Desktop.

Select an option

Save LaurentiuGabriel/5f61d95f1a230e1407ad500c93283354 to your computer and use it in GitHub Desktop.
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