English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

To be percise, I would like to use "exception handeling" to catch errors when a uer inputs a String instead of an int or double, and a double instead of an int.

I have not been able to find any good tutorials on the web. Could you please point me to some or help me in any other way? I know that this kind of thing can be hard to answer in the format of a Yahoo! Answer.

Thanks.

2007-05-15 03:33:01 · 1 answers · asked by larkale07 2 in Computers & Internet Programming & Design

1 answers

What you can do is throw your own errors when you do your type checks or value checks. You can use an existing exception type or create your own.

if (input == null) {
throw new Exception("User entered a null value.");
}

You'll need to ensure the method throws the exception and anything calling the method will need to be enclosed in a try block, catching the possible exceptions.

2007-05-15 07:37:56 · answer #1 · answered by Jim Maryland 7 · 0 0

fedest.com, questions and answers