[DOC] Doc for module Errno (#10913)

This commit is contained in:
Burdette Lamar 2024-06-05 15:27:00 -05:00 committed by GitHub
parent 33f92b3c88
commit 0b31986909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

55
error.c
View File

@ -2741,32 +2741,47 @@ syntax_error_with_path(VALUE exc, VALUE path, VALUE *mesg, rb_encoding *enc)
/* /*
* Document-module: Errno * Document-module: Errno
* When an operating system encounters an error,
* it typically reports the error as an integer error code:
* *
* Ruby exception objects are subclasses of Exception. However, * $ ls nosuch.txt
* operating systems typically report errors using plain * ls: cannot access 'nosuch.txt': No such file or directory
* integers. Module Errno is created dynamically to map these * $ echo $? # Code for last error.
* operating system errors to Ruby classes, with each error number * 2
* generating its own subclass of SystemCallError. As the subclass
* is created in module Errno, its name will start
* <code>Errno::</code>.
* *
* The names of the <code>Errno::</code> classes depend on the * When the Ruby interpreter interacts with the operating system
* environment in which Ruby runs. On a typical Unix or Windows * and receives such an error code (e.g., +2+),
* platform, there are Errno classes such as Errno::EACCES, * it maps the code to a particular Ruby exception class (e.g., +Errno::ENOENT+):
* Errno::EAGAIN, Errno::EINTR, and so on.
* *
* The integer operating system error number corresponding to a * File.open('nosuch.txt')
* particular error is available as the class constant * # => No such file or directory @ rb_sysopen - nosuch.txt (Errno::ENOENT)
* <code>Errno::</code><em>error</em><code>::Errno</code>.
* *
* Errno::EACCES::Errno #=> 13 * Each such class is:
* Errno::EAGAIN::Errno #=> 11
* Errno::EINTR::Errno #=> 4
* *
* The full list of operating system errors on your particular platform * - A nested class in this module, +Errno+.
* are available as the constants of Errno. * - A subclass of class SystemCallError.
* - Associated with an error code.
*
* Thus:
*
* Errno::ENOENT.superclass # => SystemCallError
* Errno::ENOENT::Errno # => 2
*
* The names of nested classes are returned by method +Errno.constants+:
*
* Errno.constants.size # => 158
* Errno.constants.sort.take(5) # => [:E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, :EADV]
*
* As seen above, the error code associated with each class
* is available as the value of a constant;
* the value for a particular class may vary among operating systems.
* If the class is not needed for the particular operating system,
* the value is zero:
*
* Errno::ENOENT::Errno # => 2
* Errno::ENOTCAPABLE::Errno # => 0
* *
* Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
*/ */
static st_table *syserr_tbl; static st_table *syserr_tbl;