wood burning stoves*
The moose likes Beginning Java and the fly likes What is the output of the program?please explain.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the output of the program?please explain...." Watch "What is the output of the program?please explain...." New topic
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: 2902
    
    1

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: 36578
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the output of the program?please explain....
 
Similar Threads
Doubt on thread
Threads-help
SYnchronization
wait() and synchronization doubt
Threads trying to get InterruptedException