This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Variable exception target" Watch "Variable exception target" New topic
Author

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
Greenhorn

Joined: Oct 16, 2001
Posts: 14
Hi,
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 ]

http://home.arcor.de/hirnstrom/bewerbung
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.
 
 
subject: Variable exception target
 
Similar Threads
@Resource injection problem with JNDI
Save data and Delete rows from JTable
Threading guidance to avoid potential deadlock...
PersistenceService
Static final blank variable