Throwing A Character Exception
Hello, Im looking for an example of how to throw an exception for an input string that;
rejects characters in the alphabet such as "abc..."
and only accepts numbers in the form of "1 2 3.."
Im fairly new to java and Im just looking for a solid example of this code.:(y):
-Nelson
Re: Throwing A Character Exception
You can learn how to throw exceptions at the Java Exceptions tutorial which you can find here: Exceptions tutorial
Re: Throwing A Character Exception
Write a method that tests if a given string has the form you want. For instance it might be enough to use the String methods to test the string one character at a time. Then you can call the method you have written and throw an exception if you want to.
-----
I am assuming this a homework problem as there are builtin methods like parseInt() or valueOf(), to parse a string to see if it might represent a valid number.
Re: Throwing A Character Exception
Awesome thanks so much! I'll post a reply back once I figure it out
Re: Throwing A Character Exception
There's plenty to read about - both scanning the string, and throwing exceptions. No-one here wants to take away the fun you can have discovering things by reading tutorials and documentation, but that doesn't mean you're stuck on your own trying to figure things out. Post if what you read doesn't make sense. Or post what you've tried if it isn't quite doing what you want.