aspose file tools*
The moose likes Beginning Java and the fly likes Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception handling" Watch "Exception handling" New topic
Author

Exception handling

Sasha Hernandez
Greenhorn

Joined: Oct 14, 2003
Posts: 21
Suppose you had the following code:
method_A();
try{
method_B();
method_C();
}
catch(Exception)
{
}
method_D();
If method_A() were to throw an exception and the catch block handled it, would program execution continue with the statements in the try block or would it continue after the catch block?
If method_B() were to throw an exception and the catch block handled it, would program execution continue with method_C() or with method_D()?
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
Q1 exception will be thrown, but there isn't try/catch for it in
your scrap of code.
Q2 D.
[ December 07, 2003: Message edited by: Igor Ko ]
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Dear Sasha,
I think you are confused with the try and catch block.
The simple concept of exception handling is that

The code outside the try block is never goin to be catched. If it throws the exception, defalt exception handling with catch that. That means try is for telling the java to do something different(catch), if the code in try makes some exception.
Second point for exception handling is if there is some exception at some code in try block, catch will handle it and the flow goes after catch statement. That means if there is some error in "some-code1", catch will run and then the outside-code1.
So answer for ur questions is
1) If method_A() were to throw an exception, the default handler will catch it, the program will stop and nothing will run after that.
2)If method_B() were to throw an exception and the catch block handled it, program execution continue with method_D()

Hope this is clear.


SCJP 5.0
http://sites.google.com/site/duddlutechnologies/home
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Sasha, perhaps the best answers to such questions are the ones that you discover for yourself by writing an example program or two, and seeing what happens.
Can you write a program to discover the correct answers?
[ December 08, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception handling