| Author |
What is the output of the program?please explain....
|
Krishna prasad ambala
Greenhorn
Joined: Jul 03, 2008
Posts: 11
|
|
What is the output of the program? if the run() method executes and enters into try block will it throw any exception......if not.explain why. i have an idea that sleep() will throw InterruptedException..then why it is not printing inturruptedexception.
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Have you try to execute it, What it shows when it runs !
if the run() method executes and enters into try block will it throw any exception......if not.explain why.
The exception will be thrown only if there is any runtime anomalies occurred !
i have an idea that sleep() will throw InterruptedException..then why it is not printing inturruptedexception.
Yes, the sleep() method throws InterruptedException , but that dosent mean it throws that exception , whenever we call it ! Read the docs for more explanation when it throws Exception !
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Originally posted by Krishna prasad ambala: i have an idea that sleep() will throw InterruptedException..then why it is not printing inturruptedexception.
Hi remove try and catch and check it will print(program is fine ..then why you expect Exception ) ------------- started ran ---------------
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
The Thread#sleep() method doesn't "throw" a checked Exception, it "declares" a checked Exception, telling the compiler it "might throw" an Exception. That is what the throws keyword does. If you take the try-catch away from the Thread.sleep() call, your class won't compile.
|
 |
 |
|
|
subject: What is the output of the program?please explain....
|
|
|