NumberFormatException back to the main() method?
Put your text ad here
Web hosting directory, find affordable web hosting
Data recovery software tools & file recovery utilities to recover lost data
WestNIC provides reliable web hosting services
25% off cpanel web hosting and reseller hosting deals. Promo: codestyle25off
This answer is part of the Code Style premium content package. You must have a premium content subscription to log in and view the full answer to this question.
Use the premium content subscription form below for full access to all premium content FAQs, or the FAQ by email option for the answer to this FAQ only.
A: NumberFormatException is an un-checked exception. That means that the compiler will not enforce that your application catches the exception and handle the case. For example, users may enter an invalid number at runtime and the application would throw an exception and crash.
For runtime exceptions it is important that your application handles the exception in the method in which they may occur. The callers of such methods cannot be expected to know that they would throw a runtime exception and so catch the exception. Your methods should include validation and handling for specific, anticipated runtime exceptions.
If you want to signal a problem that cannot be handled locally by your method, you should catch the runtime exception and throw a checked exception, as below. This is a typical case for creating your own checked exception type, though rather heavyweight for this simple example.
… premium content omitted
Get full access to all FAQs, subscribe now for $40
How can I throw a NumberFormatException back to the main() method?
You must make a subscription payment to access areas flagged premium content. Use the form below to create an account via PayPal.
The PayPal service allows you to pay securely and independently in your own currency. Payments are billed to Metacentric Internet Limited. We never handle your credit card details.
The Code Style site has accumulated 8 years' worth of answers to the most common Web development questions. Answers are written in clear English with examples and links to other Web resources. Your subscription provides full answers to all premium content questions listed below and other FAQ sections, plus:
double up to an int? (stub article)
NumberFormatException back to the main() method? (stub article)
wait() method defined in? (stub article)
wait and sleep methods? (stub article)
run() method in Runnable work? (stub article)
Thread is runnable, how does that work? (stub article)
public static void main(String[]) mean? (stub article)
main()? (stub article)
println overloading or overriding? (stub article)
hashCode() used? (stub article)
NullPointerException in Java? (stub article)
Rectangle on a Graphics instance? (stub article)
new operator? (stub article)
Class.forName() method and the new operator? (stub article)
Class.forName() scheme? (stub article)
newInstance()? (stub article)
Class.forName() runtime polymorphism? (stub article)
Class.forName(dbDriver) work with DriverManager.getConnection? (stub article)
== operator doesn't match strings correctly! (stub article)
+ operator is not overloaded in Java! (stub article)
StringBuffers match? (stub article)
StringBuffer? (stub article)
StringTokenizer for? (stub article)
Statement and PreparedStatement? (stub article)
PreparedStatement? (stub article)
equals and ==? (stub article)
Hello.java? (stub article)