Honeybadger now supports causes / nested exceptions

Ruby 2.1 and later support nested exceptions via the Exception#cause method. Now you can view these for any error reported to Honeybadger. This post gives a brief introduction to exception causes in Ruby, and shows you what they look like in the Honeybadger UI.

What happens when you rescue an exception and re-raise another one? It used to be that the original exception was lost forever. But since Ruby 2.1, you can access these nested exceptions via the cause method.

I've already published a more detailed look at causes, but for now a simple example will work. In the code below we raise three nested exceptions, then use the Exception#cause method to access them.

def caused_exception
      raise RuntimeError.new("This is the root cause raised at #{ Time.now }")
      raise RuntimeError.new("This is the second cause raised at #{ Time.now }")
    raise RuntimeError.new("This is the third cause raised at #{ Time.now }")

rescue => e
  puts e              # This is the third cause raised at 2015-08-04 10:07:11 -0700
  puts e.cause        # This is the second cause raised at 2015-08-04 10:07:11 -0700
  puts e.cause.cause  # This is the root cause raised at 2015-08-04 10:07:11 -0700

Viewing causes in Honeybadger

As of today, any error reported to Honeybadger will have its cause information attached. You'll find it right underneath the main backtrace in a section titled "Nested Exceptions". The only thing you need to do is to make sure that you're running the latest version of our gem.

Here's what the exception shown above would look like:


Each cause has its own separate backtrace which you can expand by clicking. You have direct links to your git repo and to open the file in a local editor, just like the "normal" backtrace.


What to do next:
  1. Try Honeybadger for FREE
    Honeybadger helps you find and fix errors before your users can even report them. Get set up in minutes and check monitoring off your to-do list.
    Start free trial
    Easy 5-minute setup — No credit card required
  2. Get the Honeybadger newsletter
    Each month we share news, best practices, and stories from the DevOps & monitoring community—exclusively for developers like you.
    author photo

    Starr Horne

    Starr Horne is a Rubyist and Chief JavaScripter at Honeybadger.io. When she's not neck-deep in other people's bugs, she enjoys making furniture with traditional hand-tools, reading history and brewing beer in her garage in Seattle.

    More articles by Starr Horne
    Stop wasting time manually checking logs for errors!

    Try the only application health monitoring tool that allows you to track application errors, uptime, and cron jobs in one simple platform.

    • Know when critical errors occur, and which customers are affected.
    • Respond instantly when your systems go down.
    • Improve the health of your systems over time.
    • Fix problems before your customers can report them!

    As developers ourselves, we hated wasting time tracking down errors—so we built the system we always wanted.

    Honeybadger tracks everything you need and nothing you don't, creating one simple solution to keep your application running and error free so you can do what you do best—release new code. Try it free and see for yourself.

    Start free trial
    Simple 5-minute setup — No credit card required

    Learn more

    "We've looked at a lot of error management systems. Honeybadger is head and shoulders above the rest and somehow gets better with every new release."
    — Michael Smith, Cofounder & CTO of YvesBlue

    Honeybadger is trusted by top companies like: