Comment

Comment by djur

Handy! A lot of Ruby libraries do a pretty bad job protecting their users from underlying exceptions that should be handled within the library. I'm hoping that with exception causes in Ruby 2.1, we'll see more libraries wrapping common exceptions.

Another option for dealing with sloppy exception handling by libraries is toe_tag, which we open-sourced at my work:

https://github.com/crowdcompass/toe_tag

It allows you to declare groups of exceptions that can be caught with a single rescue clause. This has been extremely useful when dealing with ActiveRecord's tendency to bubble up exceptions from the underlying drivers -- the native and JDBC drivers for Postgres raise completely different exceptions for the same errors.

In some cases, exception classes aren't enough to determine whether an exception actually should be caught. A lot of libraries end up forcing you to make decisions based on the text of the message, or on some custom method (#error_code or what have you). toe_tag helps clean up those checks too.

parent djur 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton