• 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

Simple exception handling question

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this below sample code inside a method which throws Exception:

......
int modI = 0;
try {
modI = Integer.parseInt(result.getString("mod_req").trim());
} catch (NumberFormatException x) {
modI = -1;
}
......

When the code trows a parsing exception, is it possible to have this code continue executing? Right now it just shows that there is NumberFormatException and stops executing. Thx.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As written, that's exactly what this bit of code would do: continue on using -1 for the value of mod1, as if no exception had occurred. If you're seeing some other behavior, it's because you're not showing us the real code.
 
Ulvi Cetin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want the code to use modI=-1 in case of an exception, but why does it stop executing and shows exception on the screen (java.lang.NumberFormatException: For input string: "N/A")? The whole method is too large to be posted here. Thx.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulvi Cetin:
why does it stop executing and shows exception on the screen (java.lang.NumberFormatException: For input string: "N/A")?



The little bit of code you've shown here won't do that. The NumberFormatException must be coming from another line of code. Look at the stack trace -- is there a line number? Look at the line of code it's calling out.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic