• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79828
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic