aspose file tools*
The moose likes Beginning Java and the fly likes try,catch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "try,catch" Watch "try,catch" New topic
Author

try,catch

Mukul Vashishtha
Greenhorn

Joined: Jun 27, 2007
Posts: 14
How can we print wwwwwwww(inside system.out.println)
because when it get exception it jumps to catch.
class Account{
public static void main(String[] args)
{String accn=null;
try{
int i = 1%0;
System.out.println("wwwwwww");
}
catch(Exception e){

}
}}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You can't. The other line in your program will throw a java.lang.ArithmeticException. What are you trying to achieve? Do you want to do something regardless of exceptions? If so have you come across finally blocks?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Isint that the point of a try catch, that if an exception is found in the try part it stops executing at the point of the exception, ignoring any code after the exception and "jumping" to the catch block.

So really there is no way to execute code in tehtry block after the exception occurs.

However if you had code that you always wanted to execute no matter if there is an exception or not, you could try putting it in to a finally block, you know:
Michael Jennings
Greenhorn

Joined: Jul 04, 2007
Posts: 20
well, if you really want to do it.

bad way :
change, int i = 1%0
to, float i = 1%0.0

good way :
put the println in "finally" block
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi yellowjersey -

We've found that when people use their real name as their display name things stay a lot friendlier, so I'd ask you to update your display name to match the JavaRanch policy.

Thanks, and welcome to the ranch.

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: try,catch