Skip to main content

Exception handling possible?

3 replies [Last post]
emery13
Offline
Joined: 2007-04-20

Hi,

Netbeans 6 is showing me an exception on the code below, but unfortunately the exception is not being caught.

"uncaught FX exception: java.net.ConnectException java.net.ConnectException: Connection refused: connect"

operation MyClass.connectURL(urlString:String) {
try {
do later {
var url = new URL( urlString );
var is = url.openStream();
// When connection not available, further lines are not executed
// nor does the exception get caught
...
var reader = new BufferedReader(new InputStreamReader(is));
is.close();
}
} catch (e:ConnectException) {
errorString = "Connection error.";
}
}

Does JavaFX support exception handling? Can someone please tell me how to deal with this situation?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jim_weaver
Offline
Joined: 2007-05-18

Yes, JavaFX Script does support exception handling. If you're willing, I'd suggest porting this program to compiled JavaFX Script, as the interpreted version is a prototype. I've found exception handling, and thread concurrency, to be very reliable in compiled JavaFX Script. Also, if you do have any problems, you can file an issue in JIRA, where with interpreted JavaFX Script improvements are no longer being made (again, it served as a prototype).

To help you get up to speed on compiled JavaFX Script, I'm writing a tutorial series for Sun entitled "Creating Rich Internet Apps With Compiled JavaFX Script". The first installment is at:
http://java.sun.com/developer/technicalArticles/scripting/javafx/ria_1/

In addition, the "Helping you become a JavaFXpert" weblog has lots of compiled JavaFX Script instruction and examples. I'd recommend starting with the "Converting Your Second JavaFX Script Program to Compiled Syntax" post, and working through the posts forward in time.
http://learnjavafx.typepad.com/weblog/2007/12/converting-your.html

Along the way, you'll run into the Rosetta Stone post, which is a little dated, but deals with the syntax differences. Also, the Achieving Closure post has an example of concurrency using the Thread class (as opposed to the "do/do later" that aren't going to be in compiled JavaFX Script).

In both versions of JavaFX Script, by the way, exception syntax is very similar to Java (try/catch, etc.)

Hope this helps,
Jim Weaver
bootcamp.JavaFXpert.com

emery13
Offline
Joined: 2007-04-20

OK. That seems the way to go from what I've read. I've already gone over your first tutorial on the sun site.

I just wish the compiling was better incorporated into NetBeans.

Even when I tried to run the scripted version from within Netbeans to debug the server code, NetBeans just repeatedly froze.

Thanks.

jim_weaver
Offline
Joined: 2007-05-18

Compiled JavaFX Script support in NetBeans is being developed alongside the JavaFX Script compiler, so I don't think that we'll have to wait too long for a pretty stable release of both. JavaOne seems to be a punctuation point each year. If I had to guess, I'd say that at least milestone release 3 of compiled JavaFX Script, with some degree of support within NetBeans, will be available by JavaOne. I don't work for Sun, so my prediction and 4 dollars will get you a Latte :-)

Thanks,
Jim Weaver
http://JavaFXpert.com