Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 7th, 2005, 11:05 PM   #1
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
quick question about java labels

hey....i was studying the topic of exceptions in java and how to use them..i have written this little program just to touch the problem from the practical side...however there is some issue with the label I've used...at compile time it gives me: undefined label: read_in...can u check the code out and tell me whats wrong with it...thanks in advance

import java.io.*;

public class etest
{
	public static void main(String[] args)
		throws java.io.IOException, NotALetter	
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	read_in:

		System.out.print("Enter word: ");
		String str = br.readLine();	
		try	
		{
			for(int i = 0; i < str.length(); i++)
				if(Character.isLetter(str.charAt(i)) == false)
					throw new NotALetter("no nums");
		}
		catch (NotALetter e)
		{
			break read_in;
		}

	}
}

class NotALetter extends IOException
{
	public NotALetter() {}
	public NotALetter(String str)
	{
		super(str);
	}
}
thenewkid is offline   Reply With Quote
Old Sep 8th, 2005, 1:52 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Java doesn't support labels, IIRC. But why use them? You can just give an error message or just ignore the whole error, like:
catch (NotALetter e) {

}

When an error is thrown, it will automatically skip everything what is left in the try block.
Polyphemus_ is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC