Ruby/Development/Exception

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

Exceprtion hierarchy

Object
 +--Exception
     +--NoMemoryError
     +--ScriptError
     |   +--LoadError
     |   +--NotImplementedError
     |   +--SyntaxError
     +--SecurityError         # Was a StandardError in 1.8
     +--SignalException
     |   +--Interrupt
     +--SystemExit
     +--SystemStackError      # Was a StandardError in 1.8
     +--StandardError
         +--ArgumentError
         +--FiberError        # New in 1.9
         +--IOError
         |   +--EOFError
         +--IndexError
         |   +--KeyError      # New in 1.9
         |   +--StopIteration # New in 1.9
         +--LocalJumpError
         +--NameError
         |   +--NoMethodError
         +--RangeError
         |   +--FloatDomainError
         +--RegexpError
         +--RuntimeError
         +--SystemCallError
         +--ThreadError
         +--TypeError
         +--ZeroDivisionError



exception.success? Returns true is the exit status if nil or zero.

begin
    exit(99)
rescue SystemExit => e
    print "This program "
    if e.success?
        print "did"
    else
        print "did not"
    end
    puts " succeed"
end



exc.to_s Returns the message associated with this exception

begin
    raise "The message"
rescue Exception => e
    puts e.to_s
end



status fo an exception

begin
    exit(99)
rescue SystemExit => e
    puts "Exit status is: #{e.status}"
end