Ruby/Development/Your Exception
Материал из Wiki.crossplatform.ru
create your own type of exception if you wanted to.
class BadDataException < RuntimeError end class Person def initialize(name) raise BadDataException, "No name present" if name.empty? end end
if we create our own exception classes, they need to be subclasses of either class Exception or one of its descendants.
class FileSaveError < StandardError attr_reader :reason def initialize(reason) @reason = reason end end
Ruby exception hierarchy
Exception NoMemoryError ScriptError LoadError NotImplementedError SyntaxError SignalException Interrupt StandardError ArgumentError IOError EOFError IndexError LocalJumpError NameError NoMethodError RangeError FloatDomainError RegexpError RuntimeError SecurityError SystemCallError SystemStackError ThreadError TypeError ZeroDivisionError SystemExit fatal