This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes question about exception capturing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "question about exception capturing" Watch "question about exception capturing" New topic
Author

question about exception capturing

tan kian
Ranch Hand

Joined: Apr 09, 2004
Posts: 40
hi all, i just want to know something. is there an Exception for catching enter key on a readline.charAt(0)(ie. user just presses enter without entering anything else thus passing an empty string)?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

If you write something like

and readLine() returns "" (the empty String) then yes, charAt() will throw a StringIndexOutOfBoundsException, as there is no 0th character in an empty String. Note also that at end-of-file, readLine() returns null, and you need to watch for that as well. Better to write something like


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about exception capturing
 
Similar Threads
simpleDateFormat Problems and questions
Battleships - guys please help me out!
Validating date using regex and simple date format
simple input program....or, not so simple?
catch statements