---
title: "Ruby 2.6 raises exception for else without rescue"
description:
  "Ruby 2.6 raises exception when 'else' is used inside 'begin..end' block
  without 'rescue'"
canonical_url: "https://www.bigbinary.com/blog/ruby-2.6-raise-exception-for-else-without-rescue"
markdown_url: "https://www.bigbinary.com/blog/ruby-2.6-raise-exception-for-else-without-rescue.md"
---

# Ruby 2.6 raises exception for else without rescue

Ruby 2.6 raises exception when 'else' is used inside 'begin..end' block without
'rescue'

- Author: Rohan Pujari
- Published: July 10, 2018
- Categories: Ruby 2.6, Ruby

#### Ruby 2.5

If we use `else` without `rescue` inside `begin..end` block in Ruby 2.5, it
gives a warning.

```ruby
irb(main):001:0> begin
irb(main):002:1> puts "Inside begin block"
irb(main):003:1> else
irb(main):004:1> puts "Inside else block"
irb(main):005:1> end
(irb):5: warning: else without rescue is useless
```

This warning is present as code inside `else` block will never get executed

#### Ruby 2.6

In Ruby 2.6 it will raise an exception if we use `else` without `rescue` in
`begin..end` block. This
[commit](https://github.com/ruby/ruby/commit/140512d2225e6fd046ba1bdbcd1a27450f55c233#diff-ff4e2dc4962dc25a1512353299992c8d)
changed warning into exception in Ruby 2.6. Changes made in the commit are
experimental.

```ruby
irb(main):001:0> begin
irb(main):002:1> puts "Inside begin block"
irb(main):003:1> else
irb(main):004:1> puts "Inside else block"
irb(main):005:1> end
Traceback (most recent call last):
1: from /usr/local/bin/irb:11:in `<main>'
SyntaxError ((irb):3: else without rescue is useless)
```

The Chinese version of this blog is available
[here](http://madao.me/yi-ruby-2-6-hui-zai-begin-end-dai-ma-kuai-zhong-yin-wei-bu-xie-rescue-zhi-xie-else-er-pao-chu-yi-chang-shi-yan-xing-feature).

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2.6-raise-exception-for-else-without-rescue)
