Gizmomogwai Gizmomogwai - 10 months ago 65
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