# (again) Rescue clauses on do/end blocks?

**URL:** <https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432>\
**Category:** Ruby\
**Created:** [August 25, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432 "2006-08-25T14:52:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mat\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@Mat\_S](https://www.ruby-forum.com/u/Mat_S)\
**Post date:** [August 25, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432/1 "2006-08-25T14:52:52Z")

</div>

Sorry to beat a dead horse, but I still have a question on the  
optional ‘begin’ sentiment when rescuing exceptions. It seems like  
the standing issue was with the use of it in brackets. Especially  
when deciding which exception to catch or adding an ensure.

Would this be unreasonable?

foo {  
blah  
rescue ExceptionA  
handle A  
rescue ExceptionB  
handle B  
ensure  
finish things  
}

Actually, it feels a little like a goto now that I type it out. That  
could be a bad sign…  
-Mat

---

<div class="post-metadata">

**Author:** ![Mat\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@Mat\_S](https://www.ruby-forum.com/u/Mat_S)\
**Post date:** [August 26, 2006, 12:49pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432/2 "2006-08-26T12:49:58Z")

</div>

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

> ```
> handle A
> 
> ```
> 
> rescue ExceptionB  
> handle B  
> ensure  
> finish things  
> }

## For one thing, it’s syntactically incorrect, rescue can only appear inside either a begin block, or in a method def, where def methodname acts like begin for this purpose, or as a modifier on a single statement.

Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Mat\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@Mat\_S](https://www.ruby-forum.com/u/Mat_S)\
**Post date:** [September 4, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432/3 "2006-09-04T14:46:20Z")

</div>

Rick DeNatale wrote:

> > blah  
> > inside either a begin block, or in a method def, where def methodname  
> > acts like begin for this purpose, or as a modifier on a single  
> > statement.

Yes, but he’s proposing a change in the syntax.

Hal

---

<div class="post-metadata">

**Author:** ![Mat\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@Mat\_S](https://www.ruby-forum.com/u/Mat_S)\
**Post date:** [September 4, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432/4 "2006-09-04T14:46:32Z")

</div>

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

> > > foo {  
> > > For one thing, it’s syntactically incorrect, rescue can only appear  
> > > inside either a begin block, or in a method def, where def methodname  
> > > acts like begin for this purpose, or as a modifier on a single  
> > > statement.
> 
> Yes, but he’s proposing a change in the syntax.

Well re-proposing it anyway. I’m mostly curious if there’s some  
fundamental problem with it that I’m not seeing. Since this  
particular syntax wasn’t proposed the last time the discussion went  
around.  
-Mat

---

<div class="post-metadata">

**Author:** ![Mat\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@Mat\_S](https://www.ruby-forum.com/u/Mat_S)\
**Post date:** [September 4, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432/5 "2006-09-04T14:46:33Z")

</div>

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

> > > > }
> 
> Well re-proposing it anyway. I’m mostly curious if there’s some  
> fundamental problem with it that I’m not seeing. Since this  
> particular syntax wasn’t proposed the last time the discussion went  
> around.

IIRC, Matz thinks it’s ugly (I can’t say I disagree, even though I  
desire the functionality). I think it’s one of the few cases where  
it’s worth the ugliness to be orthogonal here.

Most people won’t like how {} with rescue looks and probably switch to  
do/end if the need rescue. The _only_ think I can think of is maybe:

foo { bar rescue nil }

Is that still the post version?

-austin

---

<div class="post-metadata">

**Author:** ![Mat\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@Mat\_S](https://www.ruby-forum.com/u/Mat_S)\
**Post date:** [September 4, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/again-rescue-clauses-on-do-end-blocks/66432/6 "2006-09-04T14:46:33Z")

</div>

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

> > > > > ensure  
> > > > > it’s worth the ugliness to be orthogonal here.  
> > > > > Unless we try to be orthogonal in a different way like e.g.  
> > > > > do,begin =\> {  
> > > > > end =\> }  
> > > > > rescue =\> who am I to propose something here, but a short “symbol rather  
> > > > > than keyword”  
> > > > > is in my mind, maybe let us look at some  
> > > > > enusre =\> see above

{  
stupid  
? # too overloaded cannot be used in the same line with stupid  
intelligent  
}

{  
stupid  
||| # just kidding  
intelligent  
\<\<\< # see above  
necessary  
}

{  
stupid  
?? StupidError =\> se  
intelligent  
!!  
necessary  
}

Hmm I think it was worth spelling it out =\> UGLY ☹

Robert
