> ## Content Index
> Fetch the complete content index at: https://til.codes/llms.txt
> Use this file to discover other available public pages before exploring further.

# Elegant way to silently ignore a Ruby exception
- URL: https://til.codes/which-is-the-shortest-way-to-silently-ignore-a-ruby-exception/
- Published: 2017-01-06T13:46:00.000Z
- Updated: 2017-02-16T13:47:55.000Z
- Author: Manu Ajith
- Tags: ruby, #Import 2024-07-13 21:01

I was working on a small hobby project and wanted to ignore some of the Exceptions that were raised.

The first version of the code that I wrote was something similar to:

```
def ignore_exception
   begin
     yield  
   rescue Exception
   end
end

```

and using

```
ignore_exception { puts "Ignoring Exception"; raise Exception; puts "This is Ignored" }

```

After a bit of more googling and research, I came across another clean solution provided by `ActiveSupport`

```
suppress(Exception) do
   # dangerous code here
end

```

**PS: Don't ask me why I wanted to do this, as I mentioned this was just a hobby project and will/should never go out into a production code.**

Ref: [http://api.rubyonrails.org/classes/Kernel.html#method-i-suppress](http://api.rubyonrails.org/classes/Kernel.html?ref=til.codes#method-i-suppress)