Getting a thread to throw an exception


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Getting a thread to throw an exception

Threaded View

  1. #1
    Join Date
    Oct 2005
    Posts
    2

    Getting a thread to throw an exception

    Sorry if this is in the wrong place, can a mod move it if it is?

    Is it possible to get the run method inside a thread to throw an exception?
    If I describe the problem maybe I can get some advice on a different way to go about this.

    I have a main class class1 which creates a thread (class2) and executes some code within a timelimit. If class1 takes too long the thread should throw back an exception.

    try
    {
    Class2 myThread = new Class2();
    myThread.start();

    // do some stuff here within timelimit

    }
    catch (Exception e)
    {
    e.printStackTrace();
    }

    The best I can do it to get the thread to print "time out" when the timelimit
    is over and class1 is still executing.

    The problem is, the run method of a thread cannot throw exceptions.
    Is there a way around this? Is there a better to go about what I'm doing?

    Thanks
    jjamesis
    Last edited by jjamesis; 10-12-2005 at 08:49 AM.

Similar Threads

  1. Replies: 4
    Last Post: 12-29-2008, 09:25 AM
  2. Exception in thread "main"
    By SeanB in forum Java
    Replies: 3
    Last Post: 04-02-2007, 06:51 PM
  3. Exception in thread "main"
    By Sean in forum Java
    Replies: 0
    Last Post: 03-29-2002, 08:28 PM
  4. Replies: 1
    Last Post: 10-29-2000, 05:51 PM
  5. Replies: 2
    Last Post: 10-27-2000, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center