File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to catch the exceptions thrown in the finally block. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to catch the exceptions thrown in the finally block." Watch "How to catch the exceptions thrown in the finally block." New topic
Author

How to catch the exceptions thrown in the finally block.

Narasimha Rao B.
Ranch Hand

Joined: Aug 26, 2002
Posts: 205
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.


Narasimha
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Try this


Mani
Quaerendo Invenietis
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to catch the exceptions thrown in the finally block.