Error Numbers

If you ran the ensure.rb program earlier and you were watching closely, you may have noticed something unusual when you tried to log onto a nonexistent drive (for example, on my system that might be the X:\ drive). Often, when an exception occurs, the exception class is an instance of a specific named type such as ZeroDivisionError or NoMethodError. In this case, however, the class of the exception is shown to be Errno::ENOENT.

It turns out that there is quite a variety of Errno errors in Ruby. Try disk_err.rb. This defines a method, chDisk, which attempts to log onto a disk identified by the character, aChar. So if you pass “A” as an argument to chDisk, it will try to log onto the A:\ drive. I’ve called the chDisk method three times, ...

Get The Book of Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.