ScriptError
RubyFATALCommonLoad
Non-rescuable script-level error
Quick Answer
Rescue specific subclasses (LoadError, SyntaxError) rather than ScriptError itself.
What this means
ScriptError is the parent class of LoadError, NotImplementedError, and SyntaxError. These errors indicate that a Ruby script cannot be loaded or executed correctly. They are not subclasses of StandardError and are rarely rescued directly.
Why it happens
- 1A required file has a syntax error
- 2A required file cannot be found (LoadError)
- 3Calling an unimplemented method on the platform (NotImplementedError)
Fix
Rescue specific ScriptError subclass
Rescue specific ScriptError subclass
begin require 'optional_extension' rescue LoadError puts 'Extension not available, using fallback' end
Why this works
Targeting LoadError specifically avoids masking SyntaxError, which indicates a real code defect.
Code examples
ScriptError hierarchyruby
LoadError < ScriptError # => true SyntaxError < ScriptError # => true NotImplementedError < ScriptError # => true
Rescuing broadlyruby
begin
require 'c_extension'
rescue ScriptError => e
puts "Script problem: #{e.class} — #{e.message}"
endChecking ancestryruby
ScriptError < Exception # => true ScriptError < StandardError # => false
Same error in other languages
Sources
Official documentation ↗
Ruby Core Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev