This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why won't my catch catch?

 
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
Saloon Keeper
Posts: 15272
37
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: 48917
58
  • 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