Link to home
Start Free TrialLog in
Avatar of damienm
damienmFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Compile problem

I have just started learning java and I copyed this example from a book (Java: the Compete Reference) but I cannot get it to compile properly.

class CurrentThreadDemo
{
  public static void main(String args[])
  {
    Thread t = Thread.currentThread();

    System.out.println("Current thread: " + t);
    t.setName("My Thread");
    System.out.println("After name change: " + t);

    try
    {
      for (int n = 5; n > 0; n--)
      {              
      System.out.println(n);
         Thread.sleep(1000);
      }
    }
    catch (InteruptedException e)
    {
      System.out.println("Main thread interrupted");
    }
  }
}

Line 16 I get error Interception thread must be caught in the throws clause of this method.

& Line 19 InteruptedException not found.


Thanks for your help

Damien
ASKER CERTIFIED SOLUTION
Avatar of rjackman
rjackman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of damienm

ASKER

Hi Rjackman

I figured out the answer when I was reading your answer even though your answer was not exactly the answer.

When reading your answer I noticed that I had spelt interrupted with only 1 r.

So I suppose you did give me the answer if not dirrectly.

Anyway Thanks

Damien
Avatar of rjackman
rjackman

thanx for appreciating my answer
which had performed a spellcheck for u
:):):):)
RJackman