|
-
Sep 30th, 2001, 06:39 PM
#1
Thread Starter
Dazed Member
breaking out of a method [resolved]
Does anyone if there is a way to break out of a method in Java?
I have a return statement inside of a catch block and when an exception is thrown the contents of the catch block are executed but instead of the method returning back to it's caller the code after the try{ is being executed. Is there another way to handle this?
Last edited by Dilenger4; Oct 1st, 2001 at 03:10 PM.
-
Sep 30th, 2001, 06:57 PM
#2
Member
You mean this doesn't work?
Code:
public void crashMeBaby()
{
try
{
// 1
super.badStuffThatCausesExceptions();
// 2
}
catch (Exception e)
{
// 3
return;
// 4
}
}
Which comment does it get to before nuking itself?
-
Sep 30th, 2001, 07:16 PM
#3
Thread Starter
Dazed Member
I have somthing like this...... whats happining is somthing like
Visual Basics On Error ResumeNext.
Code:
public static void X(JTextField jtf){
String filepath = jtf.getText();
try{
FileReader fr = new FileReader(filepath);
/* {
this is the code i dont want executed
*/ }
}catch(Exception e){
JOptionPane.showMessageDialog(GUI, " Unable to find file requested " + " Please try again ");
jtf.setText("");
return; // should return back to it's caller
}
}
-
Sep 30th, 2001, 07:19 PM
#4
Member
Code:
public static void X(JTextField jtf){
String filepath = jtf.getText();
try{
FileReader fr = new FileReader(filepath);
System.out.println("WOOHOO!");
}catch(Exception e){
JOptionPane.showMessageDialog(GUI, " Unable to find file requested " + " Please try again ");
jtf.setText("");
return; // should return back to it's caller
}
}
So in that example, the message isn't printed? That's completely screwed up. What JDK do you have?
-
Sep 30th, 2001, 07:27 PM
#5
Thread Starter
Dazed Member
The MessageDialog pops up fine and the JTextField is cleared
but instead of the method just returning the System.out.print
that you have would print out "WOOHOO!"
Code:
public static void X(JTextField jtf){
String filepath = jtf.getText();
try{
FileReader fr = new FileReader(filepath);
System.out.println("WOOHOO!");
}catch(Exception e){
JOptionPane.showMessageDialog(GUI, " Unable to find file requested " + " Please try again ");
jtf.setText("");
return; // should return back to it's caller
}
}
-
Sep 30th, 2001, 07:30 PM
#6
Member
Originally posted by filburt1
What JDK do you have?
-
Sep 30th, 2001, 07:31 PM
#7
Thread Starter
Dazed Member
-
Sep 30th, 2001, 07:32 PM
#8
Thread Starter
Dazed Member
I always compile from the bin, so i have to goto cd C:\jdk1.3\bin
-
Sep 30th, 2001, 07:36 PM
#9
Thread Starter
Dazed Member
I just dont see how i could be somthing that i am coding wrong.
If you have a return statement anywhere in a method it should return back to it's caller. It's like when a method throws an Exception ie..... public static void computeSquareRoot(int root) throws Exception{}
the Exception would propagate back to it's caller.
-
Sep 30th, 2001, 07:39 PM
#10
-
Sep 30th, 2001, 07:45 PM
#11
Thread Starter
Dazed Member
I posted this on Sun's site with a couple of Duke Dollars
on it so i should have a couple of responses.
-
Sep 30th, 2001, 07:46 PM
#12
Member
Originally posted by Dilenger4
I posted this on Sun's site with a couple of Duke Dollars
WOOHOO! PROGRAMMERS WORKING FOR SUN MEMORIBILIA!
-
Oct 1st, 2001, 03:11 PM
#13
Thread Starter
Dazed Member
I was missing a Bracket. Dam Brackets!
-
Oct 1st, 2001, 03:26 PM
#14
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|