[2029] in java-interest
thread.sleep and java.lang.InterruptedException
daemon@ATHENA.MIT.EDU (Janet Coursey)
Fri Sep 22 04:18:58 1995
From: Janet.Coursey@Central.Sun.COM (Janet Coursey)
Date: Thu, 21 Sep 95 18:03:40 -0600
To: java-interest@java.Eng.Sun.COM
Cc: Janet.Coursey@Central.Sun.COM
Reply-To: janet.coursey@sun.com
In the JDK prebeta1 , I get this compiler error:
javac Foo.java
Foo.java:11: Warning: Exception java.lang.InterruptedException must be caught, or it must be
declared in throws clause of this method.
thread.sleep(150);
^
for this source file called Foo.java ----
import java.lang.Thread;
import java.lang.InterruptedException;
public class Foo extends Object implements Runnable {
private Thread thread;
public void run()
// throws java.lang.InterruptedException
{
thread.sleep(150);
}
} // class Foo
But when I do what it suggests I get this compiler error:
javac Foo.java
Foo.java:8: Invalid exception class java.lang.InterruptedException in throws clause. The
exception must be a subclass of an exception thrown by void run() from interface
java.lang.Runnable.
public void run()
^
for this source---
import java.lang.Thread;
import java.lang.InterruptedException;
public class Foo extends Object implements Runnable {
private Thread thread;
public void run()
throws java.lang.InterruptedException
{
thread.sleep(150);
}
} // class Foo
Now in the JDKprebeta1, java/lang/Runnable.java,
the run() method does NOT declare any throws. So how can I possibly achieve the compiler's
recommendation to "The exception must be a subclass of an exception thrown by void run() from
interface java.lang.Runnable"?
[The run() body will actually do some work if i get past this problem; this was the smallest code to
recreate the situation.]
Thanks in advance,
Janet
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com