Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

What is the output of the program?please explain....  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
---------------
 
Marshal
Posts: 59783
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!