File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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


Mukul Vashishtha

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;
int i = 1%0;
catch(Exception e){

Paul Sturrock

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

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

Joined: Oct 14, 2002
Posts: 8898
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.


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:
subject: try,catch
jQuery in Action, 3rd edition