# A Syntax question

**URL:** <https://www.ruby-forum.com/t/a-syntax-question/91110>\
**Category:** Ruby\
**Created:** [April 4, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/a-syntax-question/91110 "2007-04-04T20:01:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [April 4, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/a-syntax-question/91110/1 "2007-04-04T20:01:54Z")

</div>

Hey Guys,

I would have thought the following two code snippets were equivalent.  
However, only the first one will raise err. Can someone explain to me  
how I should be ‘reading’ the 2nd snippet?

```
  rescue Exception => err
    begin
        RDoc::usage
    rescue SystemExit
    end
    raise err

  rescue Exception => err
    begin RDoc::usage rescue SystemExit end
    raise err

```

Sonny.

---

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [April 4, 2007, 9:36pm UTC](https://www.ruby-forum.com/t/a-syntax-question/91110/2 "2007-04-04T21:36:02Z")

</div>

On Apr 4, 1:01 pm, Sonny C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> end
> raise err
> 
> rescue Exception => err
> begin RDoc::usage rescue SystemExit end
> raise err
> 
> ```
> 
> Sonny.
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

This may be wrong, but this works:

begin  
raise err  
rescue Exception =\> err  
begin  
puts “bummer 1”  
raise err2  
rescue Exception =\> err2  
puts “bummer 1.1”  
end  
end

.vs.

begin  
raise err  
rescue Exception =\> err  
begin puts “bummer 2”; raise err2; rescue Exception =\>err2; puts  
“bummer 2.1”; end  
end

---

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [April 4, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/a-syntax-question/91110/3 "2007-04-04T21:43:42Z")

</div>

Thanks Dale. I’m not actually looking for a workaround. Snippet #1 of  
my original post does work. I’m trying to understand why snippet #2  
doesn’t.

The only difference between the two are the whitespaces. If someone  
could help me understand how snippet #2 is being parsed/read by the  
interpretter that would be super.

---

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [April 4, 2007, 11:22pm UTC](https://www.ruby-forum.com/t/a-syntax-question/91110/4 "2007-04-04T23:22:39Z")

</div>

Awesome. That clarifies things. Thanks Brian.

---

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [April 4, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/a-syntax-question/91110/5 "2007-04-04T23:19:12Z")

</div>

On Thu, Apr 05, 2007 at 03:01:56AM +0900, Sonny C. wrote:

> ```
> rescue SystemExit
> end
> raise err
> 
> rescue Exception => err
> begin RDoc::usage rescue SystemExit end
> raise err
> 
> ```

These are two different syntactic constructions.

```
   <expression1> rescue <expression2>

```

returns the value of , unless there is an exception in  
which  
case it returns the value of

In this construct, you cannot specify the exception class. I think it  
only  
catches StandardError and subclasses.

Typical usage:

```
 foo rescue nil # just ignore StandardError

 a = foo rescue bar rescue baz # return value from foo, if 

```

exception  
# then bar, if exception then baz

Regards,

Brian.
