On Tuesday 16 November 2004 13:15, Bernhard Messer wrote: > >On Monday 15 November 2004 13:47, Bernhard Messer wrote: > >>Hi, ... > >The reason this is sometimes useful is that knowledge about nested > > exception is very useful for debugging; especially line numbers. > > (in my case I use it to keep Woodstox XML-parser 1.2 compatible, while > > using LinkedHashMap, and nested exceptions, if possible) > > > >The solution is not a one-liner though (if someone is interested, let me > > know and I can point you to the source code), so maybe it's easier to > > just "dumb it down" to using String constructor. But I just thought I'll > > mention that it can be completely resolved if it seems worthwhile. :-) > > you're right, i like the idea creating a nested exception. For the > particular case, it would be enough to create a NestedRuntimeException > which works under both JVM's.
Or, the alternate way; 1.4 has Throwable.initCause(), so that you can do: ... } catch (IOException ie) { Throwable t = new RuntimeException("Problems!!!"); t.initCause(ie); throw t; } instead of } catch (IOException ie) { throw new RuntimeException("Problems", ie); } And because of this, you can create a simple utility method that (a) Takes two Throwables as arguments (new exception to throw, the nested exception) (b) Uses reflection to find method Throwable.initCause(); catching NoSuchMethodException for 1.3 (c) If (b) returns (non-null), call Method on the first Throwable, passing second one as argument. This utility method can actually be called either from code that constructs the exception; or in case of a derived exception, from its constructor. Above may sound more complicated than it really is.... it's less than 10 lines of code, all in all. Anyway, I don't have a strong preference either way, but if someone feels it worth pursuing, feel free to implement the idea :-) -+ Tatu +- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]