Results 1 to 5 of 5
  1. #1
    Mnelson is offline Member
    Join Date
    Jun 2012
    Posts
    11
    Rep Power
    0

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

    -Nelson

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Throwing A Character Exception

    You can learn how to throw exceptions at the Java Exceptions tutorial which you can find here: Exceptions tutorial

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

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

  4. #4
    Mnelson is offline Member
    Join Date
    Jun 2012
    Posts
    11
    Rep Power
    0

    Default Re: Throwing A Character Exception

    Awesome thanks so much! I'll post a reply back once I figure it out

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

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

Similar Threads

  1. program throwing write exception
    By devish in forum Advanced Java
    Replies: 2
    Last Post: 10-24-2011, 11:01 AM
  2. Program not throwing exception
    By aedara in forum New To Java
    Replies: 3
    Last Post: 06-28-2011, 06:55 AM
  3. Exception throwing
    By andy16 in forum New To Java
    Replies: 9
    Last Post: 06-07-2010, 06:57 PM
  4. Display Message Without Throwing Exception
    By kailashchandra in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-27-2008, 10:05 AM
  5. throwing Exception
    By bugger in forum New To Java
    Replies: 3
    Last Post: 11-09-2007, 10:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •