Skip to content

class Exception
inherits Reference

Represents errors that occur during application execution.

Exception and its descendants are used to communicate between raise and rescue statements in begin ... end blocks. Exception objects carry information about the exception – its type (the exception’s class name), an optional descriptive string, and optional traceback information. Exception subclasses may add additional information.

Direct known subclasses

ArgumentError Base64::Error Channel::ClosedError Compress::Deflate::Error Compress::Gzip::Error Compress::Zip::Error Compress::Zlib::Error Crypto::Bcrypt::Error Crystal::Call::RetryLookupWithLiterals Crystal::Error Crystal::SkipMacroException CSV::Error Digest::FinalizedError DivisionByZeroError Enumerable::EmptyError File::BadPatternError HTTP::FormData::Error HTTP::Server::ClientError IndexError INI::ParseException InvalidBigDecimalException InvalidByteSequenceError IO::Error JSON::Error KeyError MIME::Error MIME::Multipart::Error NilAssertionError NotImplementedError OAuth2::Error OAuth::Error OpenSSL::Error OptionParser::Exception OverflowError Path::Error RuntimeError System::Group::NotFoundError System::User::NotFoundError Time::FloatingTimeConversionError Time::Format::Error Time::Location::InvalidLocationNameError Time::Location::InvalidTimezoneOffsetError Time::Location::InvalidTZDataError TypeCastError URI::Error UUID::Error XML::Error YAML::Error

Class methods

.new(message : String? = nil, cause : Exception? = nil)

View source

Methods

#backtrace

Returns any backtrace associated with the exception. The backtrace is an array of strings, each containing “0xAddress: Function at File Line Column”.

View source

#backtrace?

Returns any backtrace associated with the exception if the call stack exists. The backtrace is an array of strings, each containing “0xAddress: Function at File Line Column”.

View source

#cause : Exception?

Returns the previous exception at the time this exception was raised. This is useful for wrapping exceptions and retaining the original exception information.

View source

#inspect(io : IO) : Nil

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
View source

#inspect_with_backtrace(io : IO) : Nil

View source

#inspect_with_backtrace : String

View source

#message : String?

View source

#to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
View source