• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

try,catch

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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){

}
}}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic