Skip to content

Commit 022ab41

Browse files
committed
[DOC] Improve Errno and SystemCallError.new
1 parent 0da2b12 commit 022ab41

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

error.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,7 @@ syntax_error_with_path(VALUE exc, VALUE path, VALUE *mesg, rb_encoding *enc)
29812981

29822982
/*
29832983
* Document-module: Errno
2984-
2984+
*
29852985
* When an operating system encounters an error,
29862986
* it typically reports the error as an integer error code:
29872987
*
@@ -3022,6 +3022,13 @@ syntax_error_with_path(VALUE exc, VALUE path, VALUE *mesg, rb_encoding *enc)
30223022
* Errno::ENOENT::Errno # => 2
30233023
* Errno::ENOTCAPABLE::Errno # => 0
30243024
*
3025+
* Each class in Errno can be created with optional messages:
3026+
*
3027+
* Errno::EPIPE.new # => #<Errno::EPIPE: Broken pipe>
3028+
* Errno::EPIPE.new("foo") # => #<Errno::EPIPE: Broken pipe - foo>
3029+
* Errno::EPIPE.new("foo", "here") # => #<Errno::EPIPE: Broken pipe @ here - foo>
3030+
*
3031+
* See SystemCallError.new.
30253032
*/
30263033

30273034
static st_table *syserr_tbl;
@@ -3092,12 +3099,33 @@ get_syserr(int n)
30923099

30933100
/*
30943101
* call-seq:
3095-
* SystemCallError.new(msg, errno) -> system_call_error_subclass
3102+
* SystemCallError.new(msg, errno = nil, func = nil) -> system_call_error_subclass
30963103
*
30973104
* If _errno_ corresponds to a known system error code, constructs the
30983105
* appropriate Errno class for that error, otherwise constructs a
30993106
* generic SystemCallError object. The error number is subsequently
31003107
* available via the #errno method.
3108+
*
3109+
* If only numeric object is given, it is treated as an Integer _errno_,
3110+
* and _msg_ is omitted, otherwise the first argument _msg_ is used as
3111+
* the additional error message.
3112+
*
3113+
* SystemCallError.new(Errno::EPIPE::Errno)
3114+
* #=> #<Errno::EPIPE: Broken pipe>
3115+
*
3116+
* SystemCallError.new("foo")
3117+
* #=> #<SystemCallError: unknown error - foo>
3118+
*
3119+
* SystemCallError.new("foo", Errno::EPIPE::Errno)
3120+
* #=> #<Errno::EPIPE: Broken pipe - foo>
3121+
*
3122+
* If _func_ is not +nil+, it is appended to the message with "<tt> @ </tt>".
3123+
*
3124+
* SystemCallError.new("foo", Errno::EPIPE::Errno, "here")
3125+
* #=> #<Errno::EPIPE: Broken pipe @ here - foo>
3126+
*
3127+
* A subclass of SystemCallError can also be instantiated via the
3128+
* +new+ method of the subclass. See Errno.
31013129
*/
31023130

31033131
static VALUE

0 commit comments

Comments
 (0)