summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorBurdette Lamar <[email protected]>2024-06-05 15:27:00 -0500
committerGitHub <[email protected]>2024-06-05 16:27:00 -0400
commit0b31986909eaccb6b5f8f99f9ab2a458170a21af (patch)
treef697c15d9b36f7f4f8e784aa42838f6f3b9c8515 /error.c
parent33f92b3c88e8f03ec2aaf9db762e1eea845bee10 (diff)
[DOC] Doc for module Errno (#10913)
Diffstat (limited to 'error.c')
-rw-r--r--error.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/error.c b/error.c
index bb063a1772..fae9038ea9 100644
--- a/error.c
+++ b/error.c
@@ -2741,32 +2741,47 @@ syntax_error_with_path(VALUE exc, VALUE path, VALUE *mesg, rb_encoding *enc)
/*
* Document-module: Errno
+
+ * When an operating system encounters an error,
+ * it typically reports the error as an integer error code:
+ *
+ * $ ls nosuch.txt
+ * ls: cannot access 'nosuch.txt': No such file or directory
+ * $ echo $? # Code for last error.
+ * 2
+ *
+ * When the Ruby interpreter interacts with the operating system
+ * and receives such an error code (e.g., +2+),
+ * it maps the code to a particular Ruby exception class (e.g., +Errno::ENOENT+):
+ *
+ * File.open('nosuch.txt')
+ * # => No such file or directory @ rb_sysopen - nosuch.txt (Errno::ENOENT)
+ *
+ * Each such class is:
+ *
+ * - A nested class in this module, +Errno+.
+ * - A subclass of class SystemCallError.
+ * - Associated with an error code.
+ *
+ * Thus:
*
- * Ruby exception objects are subclasses of Exception. However,
- * operating systems typically report errors using plain
- * integers. Module Errno is created dynamically to map these
- * operating system errors to Ruby classes, with each error number
- * generating its own subclass of SystemCallError. As the subclass
- * is created in module Errno, its name will start
- * <code>Errno::</code>.
+ * Errno::ENOENT.superclass # => SystemCallError
+ * Errno::ENOENT::Errno # => 2
*
- * The names of the <code>Errno::</code> classes depend on the
- * environment in which Ruby runs. On a typical Unix or Windows
- * platform, there are Errno classes such as Errno::EACCES,
- * Errno::EAGAIN, Errno::EINTR, and so on.
+ * The names of nested classes are returned by method +Errno.constants+:
*
- * The integer operating system error number corresponding to a
- * particular error is available as the class constant
- * <code>Errno::</code><em>error</em><code>::Errno</code>.
+ * Errno.constants.size # => 158
+ * Errno.constants.sort.take(5) # => [:E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, :EADV]
*
- * Errno::EACCES::Errno #=> 13
- * Errno::EAGAIN::Errno #=> 11
- * Errno::EINTR::Errno #=> 4
+ * 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:
*
- * The full list of operating system errors on your particular platform
- * are available as the constants of Errno.
+ * Errno::ENOENT::Errno # => 2
+ * Errno::ENOTCAPABLE::Errno # => 0
*
- * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
*/
static st_table *syserr_tbl;