File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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: 15082

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 8 API documentation
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: 46353
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:
subject: why won't my catch catch?
It's not a secret anymore!