mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Clarify Thread exception handling documentation [ci skip]
From djellemah (John Anderson). Fixes [Bug #12252]
This commit is contained in:
parent
48b4deb418
commit
da76c4460f
1 changed files with 19 additions and 8 deletions
27
vm.c
27
vm.c
|
@ -2975,6 +2975,11 @@ Init_VM(void)
|
||||||
*
|
*
|
||||||
* threads.each { |thr| thr.join }
|
* threads.each { |thr| thr.join }
|
||||||
*
|
*
|
||||||
|
* To retrieve the last value of a thread, use #value
|
||||||
|
*
|
||||||
|
* thr = Thread.new { sleep 1; "Useful value" }
|
||||||
|
* thr.value #=> "Useful value"
|
||||||
|
*
|
||||||
* === Thread initialization
|
* === Thread initialization
|
||||||
*
|
*
|
||||||
* In order to create new threads, Ruby provides ::new, ::start, and
|
* In order to create new threads, Ruby provides ::new, ::start, and
|
||||||
|
@ -3058,15 +3063,21 @@ Init_VM(void)
|
||||||
*
|
*
|
||||||
* === Exception handling
|
* === Exception handling
|
||||||
*
|
*
|
||||||
* Any thread can raise an exception using the #raise instance method,
|
* When an unhandled exception is raised inside a thread, it will
|
||||||
* which operates similarly to Kernel#raise.
|
* terminate. By default, this exception will not propagate to other
|
||||||
|
* threads. The exception is stored and when another thread calls #value
|
||||||
|
* or #join, the exception will be re-raised in that thread.
|
||||||
*
|
*
|
||||||
* However, it's important to note that an exception that occurs in any
|
* t = Thread.new{ raise 'something went wrong' }
|
||||||
* thread except the main thread depends on #abort_on_exception. This
|
* t.value #=> RuntimeError: something went wrong
|
||||||
* option is +false+ by default, meaning that any unhandled exception will
|
*
|
||||||
* cause the thread to terminate silently when waited on by either #join
|
* An exception can be raised from outside the thread using the
|
||||||
* or #value. You can change this default by either #abort_on_exception=
|
* Thread#raise instance method, which takes the same parameters as
|
||||||
* +true+ or setting $DEBUG to +true+.
|
* Kernel#raise.
|
||||||
|
*
|
||||||
|
* Setting Thread.abort_on_exception = true, Thread#abort_on_exception =
|
||||||
|
* true, or $DEBUG = true will cause a subsequent unhandled exception
|
||||||
|
* raised in a thread to be automatically re-raised in the main thread.
|
||||||
*
|
*
|
||||||
* With the addition of the class method ::handle_interrupt, you can now
|
* With the addition of the class method ::handle_interrupt, you can now
|
||||||
* handle exceptions asynchronously with threads.
|
* handle exceptions asynchronously with threads.
|
||||||
|
|
Loading…
Reference in a new issue