aspose file tools
The moose likes Java in General and the fly likes Resume of program Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Resume of program" Watch "Resume of program" New topic
Author

Resume of program

sandeepkumar patil
Greenhorn

Joined: Sep 18, 2009
Posts: 2
hi

Following is scenario

1 public amethod()
2 {
3 int j=45/0;// Here code will throw runtime exception
4 system.out.println("Hi");
5 }

I want to execute code of line 4 any way .

please help me how we can resume program after throwing an exception on line 3 .

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Catch the exception.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
sandeepkumar patil
Greenhorn

Joined: Sep 18, 2009
Posts: 2
I can code like this
try{
public amethod()
{
int j=45/0;// Here code will throw runtime exception
system.out.println("Hi");
}
} catch(Exception ex)
{
}

but I cant put try- catch like this

public amethod()
{
try{

int j=45/0;// Here code will throw runtime exception
catch(Exception ex)
{
}

system.out.println("Hi");
}
}
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Please put your code between the code tags.

Your code throws a ArithmeticException which is of type RuntimeException and hence unchecked.

so, you need to catch either of the two.


JDBCSupport - An easy to use, light-weight JDBC framework -
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
finally can be used even if you aren't catching an exception


Joanne
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Joanne Neal wrote:finally can be used even if you aren't catching an exception


Which is a better approach since the sysout is not an exception handling and should be executed whether or not an exception occurs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resume of program
 
Similar Threads
interrupt
Holding the program
Question on Array
java.lang.ArithmeticException
exam objective 4.3 cmd-line args to main