JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
Subject: Causing RuntimeExceptions ^^
All descriptions from Oracle's javadocs, see comment for source link.
*/
import java.nio.ByteBuffer;
import java.nio.BufferOverflowException;
public class RuntimeExceptionExamples {
public static void main(String[] args) {
RuntimeExceptionExamples r = null;
try {
System.out.println(
"1. A NullPointerException " +
"is thrown when an " +
"application attempts to " +
"use null in a case where an " +
"object is required.");
r.toString();
} catch (NullPointerException npe) {
npe.printStackTrace();
}
try {
System.out.println(
"2. An ArithmeticException " +
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run