thread safety - using deprecated stuff Bloches example.

P

puzzlecracker

public static void sneakyThrow(Throwable t){
Thread.currentThread().stop(t);
}

----It appears that you can throw exception from any point in your
code.
what does it mean?

How and why it bypasses all the exceptions? bypassed where?

it is item 43 in Java Puzzlers.

I am not quite sure what it means.

Can someone elaborate....
 
T

Thomas Hawtin

puzzlecracker said:
public static void sneakyThrow(Throwable t){
Thread.currentThread().stop(t);
}

----It appears that you can throw exception from any point in your
code.
what does it mean?

How and why it bypasses all the exceptions? bypassed where?

Exceptions aren't bypassed, but exception checking is.

For a method (in source code) to be able to throw an exception that does
not extend Error or RuntimeException, a throws clause needs to be
present. The checking is done at compile-time, not at runtime. There are
a number of ways to throw a checked exception from methods that do not
declare that exception, as detailed in the book.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top