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

Variable exception target

D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Why? Why Java restrics me using class literal instead of class variable? I want to have code working when jnlp package available and when not. Do not tell me about work around as catch Throwable and then figure if it's UnavailableServiceException. Any elegant solution of switchable using API?

Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
avaya sahu

Joined: Oct 16, 2001
Posts: 14
It seems that you are trying to play with java language feature. When catch statement is used compiler should be informed about the type of the exception so that it can check whetehr the order of catch are correct and whether it is inherited form the proper class(e.g Excpetion,RuntimeException, Throwable) by allowing class literal it will have no clue of the class type an its heirachy.

I don'tnow any elegant soln to the problem. but you can catch throwable then use reflection to check whether the exception is of expected type.
cath(Throwable th)
if (th.isAssingable(use))
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You're using the name of an Object, where a Type is expected.
That's equivalent for writing:

The compiler doesn't even look at your 'use', but claims "can't find symbol", because it is looking for that symbol only in the list of types.
[ May 23, 2005: Message edited by: Stefan Wagner ]
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Thanks, I understand you. However your illustration a bit lacking. Look in avaya sahu's sugestion.
Define your parameters as Objects and then figure out an actual class.
I agree. Here's the link:
subject: Variable exception target
It's not a secret anymore!