From 17735c9f3879145f43a3e4be0369b7117b1b7b84 Mon Sep 17 00:00:00 2001
From: Steve Vinoski
Date: Wed, 6 May 2015 23:15:04 -0400
Subject: Add enif_raise_exception
Add enif_raise_exception function to allow NIFs to raise error
exceptions holding any Erlang terms. This does not replace or
deprecate the enif_make_badarg function, though, because raising
badarg errors is so idiomatic in NIFs. Reimplement enif_make_badarg on
top of enif_raise_exception. Add new tests for enif_raise_exception
for both normal and dirty NIFs. Add documentation for
enif_raise_exception.
---
erts/doc/src/erl_nif.xml | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
(limited to 'erts/doc')
diff --git a/erts/doc/src/erl_nif.xml b/erts/doc/src/erl_nif.xml
index 155aee2f42..104d90c937 100644
--- a/erts/doc/src/erl_nif.xml
+++ b/erts/doc/src/erl_nif.xml
@@ -787,7 +787,8 @@ typedef enum {
enif_make_badarg is called to set a
pending badarg exception, a subsequent call to enif_has_pending_exception(env, &reason)
will set reason to the atom badarg, then return true.
- See also: enif_make_badarg.
+ See also: enif_make_badarg
+ and enif_raise_exception.
intenif_inspect_binary(ErlNifEnv* env, ERL_NIF_TERM bin_term, ErlNifBinary* bin)
@@ -902,12 +903,13 @@ typedef enum {
it calls invokes enif_make_badarg, the runtime ensures that a
badarg exception is raised when the NIF returns, even if the NIF
attempts to return a non-exception term instead.
- The return value from enif_make_badarg may only be used as
- return value from the NIF that invoked it (direct or indirectly)
+ The return value from enif_make_badarg may be used only as the
+ return value from the NIF that invoked it (directly or indirectly)
or be passed to
enif_is_exception, but
not to any other NIF API function.
- See also: enif_has_pending_exception.
+
See also: enif_has_pending_exception
+ and enif_raise_exception
In earlier versions (older than erts-7.0, OTP 18) the return value
from enif_make_badarg had to be returned from the NIF. This
@@ -1174,6 +1176,19 @@ typedef enum {
reload or upgrade.
Was previously named enif_get_data.
+ ERL_NIF_TERMenif_raise_exception(ErlNifEnv* env, ERL_NIF_TERM reason)
+ Raise a NIF error exception
+ Create an error exception with the term reason to be returned from a NIF,
+ and associate it with the environment env. Once a NIF or any function it calls
+ invokes enif_raise_exception, the runtime ensures that the exception it creates
+ is raised when the NIF returns, even if the NIF attempts to return a non-exception
+ term instead. The return value from enif_raise_exception may be used only as
+ the return value from the NIF that invoked it (directly or indirectly) or be passed
+ to enif_is_exception, but
+ not to any other NIF API function.
+ See also: enif_has_pending_exception
+ and enif_make_badarg.
+
intenif_realloc_binary(ErlNifBinary* bin, size_t size)
Change the size of a binary.
Change the size of a binary bin. The source binary
--
cgit v1.2.3