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 Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exceptions" Watch "Exceptions" New topic


Igor Merabishvili

Joined: Apr 17, 2008
Posts: 3
Is there any logic in the fact that FileNotFoundException is not a RuntimeException but NumberFormatException is?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

FileNotFoundException is not a RuntimeException

Right, because, sometimes the file your using may not present or mistakenly deleted , so it always safe to confirm whether a file is present or not , Hence compiler forced us to handle it ( called checked exception )

but NumberFormatException is?

when you parse an integer or any primitive data type thru wrapper class static method like parsetInt , you know only numeric data is present in string and you can parse it.

Hope this help ..


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The previous poster sort-of explained it, but without giving the background.

In general RuntimeException is for non-fatal[*] conditions that generally indicate a programming bug. For instance, dereferencing null reference, reading off the end of an array etc.

Checked Exceptions are for conditions that generally represent a problem with data or with the underlying system. For instance, a required disk file is not found (FileNotFoundException). Such conditions are typically not the direct result of a programming bug.

NumberFormatException is difficult to categorise, as it depends where the string being parsed comes from. If it comes directly from user input, a checked exception might be appropriate. If it was obtained programmatically, a RuntimeException might be appropriate. The Java designers picked a RuntimeException.

Don't lose sleep over it.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Igor Merabishvili

Joined: Apr 17, 2008
Posts: 3
Thanks to both of you, guys.
I agree. Here's the link:
subject: Exceptions
It's not a secret anymore!