wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes why won't my catch catch? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why won Watch "why won New topic

why won't my catch catch?

Momo Sawada

Joined: Dec 10, 2010
Posts: 24
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

Joined: Aug 16, 2005
Posts: 14074

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Momo Sawada

Joined: Dec 10, 2010
Posts: 24
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

Joined: Oct 13, 2005
Posts: 37958
You don't need to stop the program; it will exit when it reaches the end of the main method.
I agree. Here's the link: http://aspose.com/file-tools
subject: why won't my catch catch?
Similar Threads
Alpha beta pruning with negamax
Checking to ensure that the keyboard input is of type int.
method takes longer each time
Counting chars during file read.