diff --git a/doc/site/error-handling.markdown b/doc/site/error-handling.markdown index d8b7012b..db04114b 100644 --- a/doc/site/error-handling.markdown +++ b/doc/site/error-handling.markdown @@ -144,6 +144,8 @@ to cause your own runtime errors to occur. This can be done by calling the You must pass in an error message, and it must be a string. +If the provided message is `null`, no runtime error is raised. + ## Failures The last flavor of errors is the highest-level one. All of the above errors diff --git a/doc/site/modules/core/fiber.markdown b/doc/site/modules/core/fiber.markdown index 201907ef..fe7b1906 100644 --- a/doc/site/modules/core/fiber.markdown +++ b/doc/site/modules/core/fiber.markdown @@ -6,6 +6,14 @@ A lightweight coroutine. [Here][fibers] is a gentle introduction. ## Static Methods +### Fiber.**abort**(message) +Raises a runtime error with the provided message, unless `message` is `null` + + :::wren + Fiber.abort(null) // Do nothing. + Fiber.abort("Something bad happened") // Raise a runtime error with provided messsage. + + ### Fiber.**current** The currently executing fiber. @@ -127,6 +135,17 @@ Invokes the fiber or resumes the fiber if it is in a paused state and sets fiber.call() fiber.call("value") //> value +### **error*** +Assuming that a fiber has raised an error, `error` returns the error message. + + :::wren + var fiber = Fiber.new { + 123.badMethod + } + + fiber.try() + System.print(fiber.error) //> Num does not implement method 'badMethod'. + ### **isDone** Whether the fiber's main function has completed and the fiber can no longer be @@ -134,6 +153,20 @@ run. This returns `false` if the fiber is currently running or has yielded. ### **transfer**() +### **try**() +Tries to run the fiber. If a runtime error occurs +in the called fiber, the error is captured and is returned as a string. + + :::wren + var fiber = Fiber.new { + 123.badMethod + } + + var error = fiber.try() + System.print("Caught error: " + error) + +If the called fiber raises an error, it can no longer be used. + **TODO** ### **transfer**(value)