# Thread interruptable too early?

**URL:** <https://www.ruby-forum.com/t/thread-interruptable-too-early/113789>\
**Category:** Ruby\
**Created:** [September 4, 2007, 11:47pm UTC](https://www.ruby-forum.com/t/thread-interruptable-too-early/113789 "2007-09-04T23:47:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [September 4, 2007, 11:47pm UTC](https://www.ruby-forum.com/t/thread-interruptable-too-early/113789/1 "2007-09-04T23:47:25Z")

</div>

Hmm. Question.

Imagine you’ve got this code:  
a = Thread.new {  
begin

# do stuff

rescue MyException  
end  
}  
a.raise MyException.new

Is it possible that this will still result in an uncaught exception  
within thread a? Thoughts?  
Thank you!  
-Roger

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [September 5, 2007, 12:03am UTC](https://www.ruby-forum.com/t/thread-interruptable-too-early/113789/2 "2007-09-05T00:03:42Z")

</div>

On Wed, Sep 05, 2007 at 06:47:29AM +0900, Roger P. wrote:

> ## Is it possible that this will still result in an uncaught exception within thread a? Thoughts? Thank you! -Roger
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Thread#raise is bad, in general, for worse reasons than that:

t = Thread.new {  
begin  
allocate\_resource()  
do\_something()  
ensure  
cleanup\_resource()  
end  
}  
sleep 1  
t.raise SomeException.new

If the thread is in cleanup when Thread#raise is called, then cleanup  
will fail, which is probably not the desired behavior.

There are plenty other examples I’ve seen as well.

Paul
