Websphere throws uncatchable exception

DWR pulls some neat tricks with backwards compatibility. We support Annotations, but can still be run from JDK 1.3. We support runtime type information from JDK 5 generics, and we can still run when java.util.logging is not present. Generally it is fairly easy – some reflection, some catching of UnsupportedClassVersionError and you’re good to go.

Except that Websphere has just thrown us a curveball. Get this:

try {
  // Use a class that uses Annotations
catch (UnsupportedClassVersionError ex) {
  // The VM does not support classes compiled with a JDK 5
  // Don't print a stack trace, in fact, ignore it.
catch (Throwable ex) {

This works just fine most place, however on Websphere 6 you get this:

java.lang.UnsupportedClassVersionError: org/directwebremoting/annotations/AnnotationsConfigurator (Unsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)

It seems like the UnsupportedClassVersionError thrown by Websphere is loaded from a different classloader than the UnsupportedClassVersionError that we are trying to catch, hence the "catch Throwable" is hit rather than the "catch UnsupportedClassVersionError".

Is this explanation possible?

Where will this madness end? Is it possible to have more than one version of java.lang.Throwable in your VM, or more than one java.lang.Object – I have to assume not because there must be a special relationship between the VM and the system classloader. Anyone have any clue what is going on?


Comments have been turned off on old posts