Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to throw exception in run method

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my thread class, when i invoke a run method, i can get an exception. I want this exception to be thrown to the method which called this thread..how do i do this..When i tried to throw exception, it is not compiling ..prompting that run method can't be overridden as throws clause has difference.
Anyone can help me in this! Thanks in advance...
If you have code samples please provide the same
thanks
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Babu,
There are two types of exception in java:
  • checked
  • unchecked

  • "checked" exceptions are checked at compile time.
    "unchecked" exceptions are not.
    Therefore your "run()" method needs to throw an unchecked exception. This section of the Java Tutorial has nore details:
    http://java.sun.com/docs/books/tutorial/essential/exceptions/throwable.html
    Basically, your "run()" method should throw an exception which is a subclass of "java.lang.RuntimeException"
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/RuntimeException.html
    Hope this helps.
    Good Luck,
    Avi.
     
    Ranch Hand
    Posts: 1170
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think an Exception is thrown upto the top of the thread in which it is thrown.
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic