![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
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);
}
} |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|