-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionExamples.java
More file actions
39 lines (29 loc) · 987 Bytes
/
ExceptionExamples.java
File metadata and controls
39 lines (29 loc) · 987 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
public class ExceptionExamples
{
public static void m1()
{
m2();
}
public static void m2()
{
m1();
}
public static void main(String[] args)
{
//m1(); -> E:java.lang.StackOverflowError
int[] x=new int[5];
System.out.println(x[0]);
//System.out.println(x[10]); -> RE:java.lang.ArrayIndexOutOfBoundsException: 10
String s=null;
//System.out.println(s.length()); -> RE:java.lang.NullPointerException
Object o=new Object();
//String s1=(String)o; -> RE:java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
//static int y=10/0; ->RE: error: illegal start of expression
Thread t=new Thread();
t.setPriority(7);
//t.setPriority(15); -> RE:java.lang.IllegalArgumentException
//int i=Integer.parseInt("ten"); -> RE:java.lang.NumberFormatException
t.start();
//t.start(); ->RE:java.lang.IllegalThreadStateException
}
}