What To Do When You Don't Rescue
Ruby's rescue
syntax supports a couple different blocks. I was already familiar with ensure
which is a block of code that will be executed regardless of whether or not an exception was rescued.
What if you want to differentiatee between an instance when your code ran without incident and when there was an exception? Ruby's rescue
syntax also supports an else
block. The else
block is executed only when nothing is rescued.
There are a lot of ways to use this. Here I was able to differentiate the messaging in my logging based on whether or not an exception occurred.
Last updated