Compile problem

Posted on 2000-03-21
Last Modified: 2008-03-17
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);

      for (int n = 5; n > 0; n--)
    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

Question by:damienm
  • 2

Accepted Solution

rjackman earned 30 total points
ID: 2640023
hi damienm

check ur code
>>catch (InteruptedException e)
                       System.out.println("Main thread interrupted");

>>InteruptedException e
it should be
catch (InterruptedException e)

always use printStackTrace() method to get the stack trace where u have gone wrong
now it will work fine

Author Comment

ID: 2640521
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


Expert Comment

ID: 2643333
thanx for appreciating my answer
which had performed a spellcheck for u

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 91
thymeleaf natural templating vs JSP 2 99
Error trying to install RTMT Win7 5 60
diffSum example 4 37
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question