This is a multi-part message in MIME format.

------extPart_000_00DF_01C35DA8.55D95060
Content-Type: text/plain;
	charsetso-8859-1"
Content-Transfer-Encoding: 7bit

Recently I was helping a colleague who was new to Ruby with a program
that was using threads. It seemed to him that for some reason that some
of the thread's were not running. First he tried adding sleeps to the
main thread to "give time" to the other threads to run, but this didn't
work. It turns out that by joining the threads in question, that there
were errors in the program that were throwing exceptions that killed the
thread -- SILENTLY.
 
I don't know if there is a better way to do this, but this is the
solution we came up with to print out any exceptions that occur in a
thread (uncaught) and exit the program.
 
require "thread"
 
class MyThread < Thread
 def initialize(*args, &block)
  super(*args) do
   begin
    block.call
   rescue Exception e
    $stderr.print "Exception occured: #{e.message} at " +
e.backtrace.join("\n")
    exit! 1
   end
  end
 end
end
 
Is there a better way?
 
Steve Tuckner

------extPart_000_00DF_01C35DA8.55D95060
Content-Type: text/html;
	charsetso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>



<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=009342117-08082003>Recently I was 
helping a colleague who was new to Ruby with a program that was using threads. 
It seemed to him that for some reason that some of&nbsp;the thread's were not 
running. First he tried adding sleeps to the main thread to "give time" to the 
other threads to run, but this didn't work. It turns out that by joining the 
threads in question, that there were errors in the program that were throwing 
exceptions that killed the thread -- SILENTLY.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=009342117-08082003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=009342117-08082003>I don't know if 
there is a better way to do this, but this is the solution we came up with to 
print out any exceptions that occur in a thread (uncaught) and exit the rogram.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=009342117-08082003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=009342117-08082003>require 
"thread"</SPAN></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=009342117-08082003>class MyThread &lt; 
Thread<BR>&nbsp;def initialize(*args, &amp;block)<BR>&nbsp;&nbsp;super(*args) 
do<BR>&nbsp;&nbsp;&nbsp;begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;block.call<BR>&nbsp;&nbsp;&nbsp;rescue 
Exception =&gt; e<BR>&nbsp;&nbsp;&nbsp;&nbsp;$stderr.print "Exception occured: 
#{e.message} at " + e.backtrace.join("\n")<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit! 
1<BR>&nbsp;&nbsp;&nbsp;end<BR>&nbsp;&nbsp;end<BR>&nbsp;end<BR>end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=009342117-08082003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=009342117-08082003>Is there a better 
way?</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=009342117-08082003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=009342117-08082003>Steve uckner</SPAN></FONT></DIV></BODY></HTML>

------extPart_000_00DF_01C35DA8.55D95060--