Gizmomogwai Gizmomogwai - 21 days ago 5
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

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


simply crashes without calling my rescue code.

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

Answer

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