I Am A Bad Coder

sleep(5000);

./ConversationScreen.java:75: 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.

3 Comments

  1. Posted November 26, 2003 at 3:26 pm | Permalink

    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?”

  2. Mike Hoye
    Posted November 26, 2003 at 6:46 pm | Permalink

    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.

  3. Posted November 26, 2003 at 7:02 pm | Permalink

    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.