File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JNLP and Web Start and the fly likes cant catch NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "cant catch NoClassDefFoundError" Watch "cant catch NoClassDefFoundError" New topic

cant catch NoClassDefFoundError

Mike Kowalski

Joined: Apr 21, 2013
Posts: 6
This is my code:

and i get:

I know that this code will only work when i lunch my app using JWS, but is there a way to catch the exception if i lunch my app using jar archiwe? I need this to find out if user is lunching my app localy (using jar archiwe) instead of lunching it through jnlp file.

Thank you very much for your time
Jacob Anawalt
Ranch Hand

Joined: Oct 27, 2010
Posts: 64

NoClassDefFoundError seems to be uncatchable because you get tripped up twice. First javax.jnlp.ServiceManager.lookup triggers the NoClassDefFoundError, but the enclosing try/catch also contains an undefined class, javax.jnlp.UnavailableServiceException.

Since those are Errors, it is generally discouraged to try and catch them anyway, so lets find another way.

I don't know the canonical way of testing if Java Web Start is active or not, but using java.lang.Class.forName seems like a good way to throw a java.lang.ClassNotFoundException instead.

I agree. Here's the link:
subject: cant catch NoClassDefFoundError
It's not a secret anymore!