Results 1 to 3 of 3
Thread: How can I use try/catch?
- 04-30-2012, 07:16 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 12
- Rep Power
- 0
How can I use try/catch?
I want to do something like
input something from text field into an integer
if that thing is not an integer, send an error message
So I was trying to use this
try{
int x = Integer.parseInt(**string from textfield here**);
}
catch (????
{
//do something error related if it doesn't work.
}
However I couldn't find a way to make it work. I tried catch(TypeMismatchException) but it said no, you can't do that, you silly boy.
What's a way to do this, or is there some other handy dandy function I'm not using?
- 04-30-2012, 07:48 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 697
- Rep Power
- 6
Re: How can I use try/catch?
You can always look at the Javadoc on how to use the class. You will find the description of what the class do. The description of each method including the parameters required by the method, the return type and the exception that might be thrown by those method.
For the Integer.parseInt(String s) method it throws the java.lang.NumberFormatException exception. For details you can find it here Integer (Java Platform SE 7 )Website: Learn Java by Examples
- 04-30-2012, 08:52 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Try and Catch's
By dougie1809 in forum New To JavaReplies: 10Last Post: 03-15-2012, 03:23 AM -
Try... Catch?
By Callofdudey in forum New To JavaReplies: 3Last Post: 10-06-2011, 09:29 PM -
try and catch
By Bimz in forum New To JavaReplies: 1Last Post: 09-26-2011, 09:44 AM -
try catch help
By vividcooper in forum New To JavaReplies: 8Last Post: 02-11-2010, 09:00 AM -
how to catch two exceptions in one catch()?
By arnab321 in forum New To JavaReplies: 1Last Post: 11-06-2008, 10:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks