This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why won't my catch catch?  RSS feed

 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again... and thank you to everyone who took the time to give advice to my very trivial questions...(sorry!)
i have a code... which looks something like this...



but i don't understand why my NumberFormatException catch block won't work... the ArithmeticException catch block works just fine..
Thank you very much!!!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's never called because inside the try { ... } block there is nothing that will ever throw a NumberFormatException.

Line 6 might throw a NumberFormatException, but it's outside the try { ... } block.

By the way, all those System.exit(0); calls are not necessary.
 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhhh... i get your meaning...
Thanks you!!!
oh, and i just wanted to put the system exits because i want the program to exit without me pressing the stop activate tool...
 
Campbell Ritchie
Sheriff
Posts: 53764
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to stop the program; it will exit when it reaches the end of the main method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!