This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Igor Merabishvili
Greenhorn

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: 2902
    
    1



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 )



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 ..

Regards,


[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
Greenhorn

Joined: Apr 17, 2008
Posts: 3
Thanks to both of you, guys.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exceptions