Compile problem

Posted on 2000-03-21
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

rjackman earned 90 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

743 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