Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab2fdce

Browse files
Add files via upload
1 parent ecd100c commit ab2fdce

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
/**
3+
* ExceptionHandling1
4+
*/
5+
class ExceptionHandling1 {
6+
public static void main(String[] args) {
7+
int d,a;
8+
try{
9+
d=0;
10+
a=42/d;
11+
}
12+
catch(ArithmeticException e){
13+
System.out.println("By printStackTrace() method");
14+
e.printStackTrace();//we will get name(e.g. java.lang.ArithmeticException) and
15+
// description(e.g. / by zero) of an exception separated by colon, and stack
16+
// trace (where in the code, that exception has occurred) in the next line.
17+
System.out.println(e);
18+
System.out.println("by toString() mrthod");//we will only get name and description of an exception. Note that this method is overridden in Throwable class.
19+
20+
System.out.println(e.toString());
21+
22+
System.out.println("By getMessage()");// we will only get description of an exception.
23+
System.out.println(e.getMessage());
24+
25+
}
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /