W3cubDocs

/Crystal

class Exception

Overview

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

Defined in:

exception.cr

Constructors

Instance Method Summary

Constructor Detail

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

Instance Method Detail

def backtraceSource

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

def backtrace?Source

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”.

def cause : Exception?Source

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

def inspect(io : IO) : NilSource

Description copied from class Reference

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>

def inspect_with_backtrace(io : IO) : NilSource

def inspect_with_backtrace : StringSource

def message : String?Source

def to_s(io : IO) : NilSource

Description copied from class Reference

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>

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Exception.html