• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to catch the exceptions thrown in the finally block.

 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Any one of you can explain how to catch the exceptions thrown in the finally block.
Code:
===================================================================
1 public class TestException1{
2public static void main(String args[]){
3int j=5,k=0,l;
4int[] array = new int[2];
5try{
6l=j/k;
7}
8catch(ArithmeticException e){
9System.out.println("ArithmeticException thrown");
10}
11finally{
12l=array[3];
13}
14try{}
15catch(ArrayIndexOutOfBoundsException e){
16System.out.println("ArrayIndexOutOfBoundsException thrown ");
17}
18}
19 }
===================================================================
When i ran the above code, message in the line number 16, is not displaying, means exception thrown at the line 12 is not catching on line 15. If i delete the line no 14 i.e., try{} block, catch block with out try block compile time error is throwing.
Can any of u explain, how to catch the exceptions thrown in the finally block with an example.
Many Thanks in advance.
Narasimha.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic