This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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.
 
Similar Threads
Exceptions exercise
try /catch problem?
2 objects EXCEPTION
Best way to get input
exception handling