# Test and exceptions

**URL:** <https://www.ruby-forum.com/t/test-and-exceptions/68061>\
**Category:** Ruby\
**Created:** [September 8, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/test-and-exceptions/68061 "2006-09-08T20:30:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 8, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/test-and-exceptions/68061/1 "2006-09-08T20:30:51Z")

</div>

Hi

In the file testcase.rb that is part of the Test module why are only the  
AssertionFailedError, StandardError and ScriptError exceptions caught?

Shouldn’t snippet one (see below) be changed to snippet two (see below)?

Thanks

Snippet One:

begin  
setup  
**send** (@method\_name)  
rescue AssertionFailedError =\> e  
add\_failure(e.message, e.backtrace)  
rescue StandardError, ScriptError  
add\_error($!)  
ensure  
begin  
teardown  
rescue AssertionFailedError =\> e  
add\_failure(e.message, e.backtrace)  
rescue StandardError, ScriptError  
add\_error($!)  
end  
end

Snippet Two:

begin  
setup  
**send** (@method\_name)  
rescue AssertionFailedError =\> e  
add\_failure(e.message, e.backtrace)  
rescue Object  
add\_error($!)  
ensure  
begin  
teardown  
rescue AssertionFailedError =\> e  
add\_failure(e.message, e.backtrace)  
rescue Object  
add\_error($!)  
end  
end

Here’s the run method that is part of the testcase class …

def run(result)  
yield(STARTED, name)  
@\_result = result  
begin  
setup  
**send** (@method\_name)  
rescue AssertionFailedError =\> e  
add\_failure(e.message, e.backtrace)  
rescue Object #StandardError, ScriptError  
add\_error($!)  
ensure  
begin  
teardown  
rescue AssertionFailedError =\> e  
add\_failure(e.message, e.backtrace)  
rescue Object #StandardError, ScriptError  
add\_error($!)  
end  
end  
result.add\_run  
yield(FINISHED, name)  
end

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 8, 2006, 9:16pm UTC](https://www.ruby-forum.com/t/test-and-exceptions/68061/2 "2006-09-08T21:16:56Z")

</div>

On 9/8/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi
> 
> In the file testcase.rb that is part of the Test module why are only the  
> AssertionFailedError, StandardError and ScriptError exceptions caught?
> 
> Shouldn’t snippet one (see below) be changed to snippet two (see below)?

This was discussed on ruby-core, topic “test/unit doesn’t rescue a  
Exception”, but it seems it’s not commited yet.

Good point anyway 😉
