diff --git a/ext/numo/linalg/mkmf_linalg.rb b/ext/numo/linalg/mkmf_linalg.rb
index <HASH>..<HASH> 100644
--- a/ext/numo/linalg/mkmf_linalg.rb
+++ b/ext/numo/linalg/mkmf_linalg.rb
@@ -23,10 +23,12 @@ def create_site_conf
       Fiddle.dlopen "libm.so"
     rescue
       (5..7).each do |i|
-        Fiddle.dlopen "libm.so.#{i}"
-        need_version = true
-        break
-      rescue
+        begin
+          Fiddle.dlopen "libm.so.#{i}"
+          need_version = true
+          break
+        rescue
+        end
       end
       if !need_version
         raise "failed to check whether dynamically linked shared object needs version suffix"
rescue in block is not valid for ruby version <= <I>