Ruby - Exception Error number

Introduction

To see a complete list of Errno constants, run this:

Demo

puts( Errno.constants )

Result

There is quite a variety of Errno errors in Ruby.

Demo

def chDisk( aChar )
    startdir = Dir.getwd#   w  w  w  .  j  a v  a  2s  .  c  om
    begin
        Dir.chdir( "#{aChar}:\\" )
        puts( `dir` )
    rescue Exception => e
        #showFamily( e.class ) # to see ancestors, uncomment
        puts e.class           # ...and comment out this
        puts e
    ensure
        Dir.chdir( startdir )
    end
end

chDisk( "F" )
chDisk( "X" )
chDisk( "ABC" )

Result

To view the corresponding numerical value of any given constant, append ::Errno to the constant name, like this:

Errno::EINVAL::Errno

You can use the following code to display a list of all Errno constants along with their numerical values:

Demo

for err in Errno.constants do
   errnum = eval( "Errno::#{err}::Errno" )
   puts( "#{err}, #{errnum}" )
end# from  w w  w  .j  a v  a2s. c  o  m

Result

Related Topic