November 26, 2003

I Am A Bad Coder

Filed under: digital — mhoye @ 3:05 pm


./ unreported exception e java.lang.InterruptedException; must be caught or declared to be thrown

Ah, very well then. Here:

try { sleep(5000); } catch(Exception a){ sleep(5000) ; }

I mean just fucking do it, already. Why do sleep() and wait() need to throw exceptions?

try { sleep(5000); } catch(Exception a){ /*Fuck you, Java! */ }

I am clearly not very good at this.


  1. You just might want to figure out what the exception is….
    “You slept with her?”
    “No. Who could sleep with all that sex going on?”

    Comment by Alex — November 26, 2003 @ 3:26 pm

  2. The error it throws is an InterruptedException.

    Perhaps this is my ignorance, but I cannot imagine a situation in which you would wake up a sleeping thread and doing so would be an error.

    Comment by Mike Hoye — November 26, 2003 @ 6:46 pm

  3. They throw exceptions when the thread has its interrupt() method called, which can be done by other threads (such as a resource manager) or by the VM. Generally it’s better practise to use a wait()/notify() cycle to wake up threads with a resource manager, but sometimes people get lazy and use the interrupt(). interrupt() is the only way to wake up a sleep()ing thread.

    The “de rigeur” way of dealing with the exception (which basically admits that the interrupt() method call is a hack) is to use a catch {//do nothing!} block.

    I seriously can’t believe I remembered all that.

    Comment by Mike B — November 26, 2003 @ 7:02 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress