Gizmomogwai Gizmomogwai - 1 year ago 131
Ruby Question

How to rescue from incompatible library version ... (fatal) in ruby

I require a native extension, that is in my filesystem but not compatible with my current system. In this case I want to react in ruby and use a mock implementation, but this code

require 'dotstar'
rescue LoadError
puts "Got LoadError"
require 'dotstarsimulator'
puts "Warning: could not open dotstar native support => using sim"
require 'dotstarsimulator'

simply crashes without calling my rescue code.

Same for an irb session, in which I just try to
require 'dotstar'

Answer Source

Looks like this is a duplicate of: How do I rescue from a `require': no such file to load in ruby?

You have to specifically resque LoadError

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download