Archie Cobbs wrote:
> Stuart Ballard wrote:
> > Jeroen pointed out to me a while back that you can use 
> generics to throw an
> > unchecked exception:
> 
> There's also a way to do this without using JDK 1.5 stuff, but it's
> even uglier :-)
> 
> Construct a class (dynamically) that has a default constructor
> that simply throws whatever exception you want. Then invoke
> Class.newInstance() on the class.

That doesn't work for all exception types (specifically not the ones
that Class.newInstance declares).

Here's the simplest way to do it:

   Thread.currentThread().stop(someCheckedException);

Thread.stop is deprecated because it is unsafe to throw asynchronous
exception, but that doesn't apply to throwing (synchronous) exceptions
on the current thread, so hopefully most VMs will implement that.

Regards,
Jeroen


_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to