Skip to content

Instantly share code, notes, and snippets.

@mriddle
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mriddle/69ab03de51389b868b66 to your computer and use it in GitHub Desktop.
Save mriddle/69ab03de51389b868b66 to your computer and use it in GitHub Desktop.
Print out an up-to-date list of the Ruby exception hierarchy
BasicObject
Exception
MonitorMixin::ConditionVariable::Timeout
NoMemoryError
ScriptError
LoadError
Gem::LoadError
NotImplementedError
SyntaxError
SecurityError
SignalException
Interrupt
StandardError
ArgumentError
Gem::Requirement::BadRequirementError
EncodingError
Encoding::CompatibilityError
Encoding::ConverterNotFoundError
Encoding::InvalidByteSequenceError
Encoding::UndefinedConversionError
FiberError
IOError
EOFError
IndexError
KeyError
StopIteration
LocalJumpError
Math::DomainError
NameError
NoMethodError
RangeError
FloatDomainError
RegexpError
RuntimeError
Gem::Exception
Gem::CommandLineError
Gem::DependencyError
Gem::DependencyRemovalException
Gem::DependencyResolutionError
Gem::DocumentError
Gem::EndOfYAMLException
Gem::FilePermissionError
Gem::FormatException
Gem::GemNotFoundException
Gem::SpecificGemNotFoundException
Gem::GemNotInHomeException
Gem::ImpossibleDependenciesError
Gem::InstallError
Gem::InvalidSpecificationException
Gem::OperationNotSupportedError
Gem::RemoteError
Gem::RemoteInstallationCancelled
Gem::RemoteInstallationSkipped
Gem::RemoteSourceException
Gem::RubyVersionMismatch
Gem::UnsatisfiableDependencyError
Gem::VerificationError
SystemCallError
Errno::EAGAIN
IO::WaitReadable
IO::EAGAINWaitReadable
IO::WaitWritable
IO::EAGAINWaitWritable
Errno::EINPROGRESS
IO::WaitReadable
IO::EINPROGRESSWaitReadable
IO::WaitWritable
IO::EINPROGRESSWaitWritable
ThreadError
TypeError
ZeroDivisionError
SystemExit
Gem::SystemExitException
SystemStackError
fatal
#!/usr/bin/env ruby
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
end
indent = 0
tree_printer = Proc.new do |t|
t.keys.sort { |c1,c2| c1.name <=> c2.name }.each do |k|
space = (' ' * indent); space ||= ''
puts space + k.to_s
indent += 2; tree_printer.call t[k]; indent -= 2
end
end
tree_printer.call tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment