From b02f03c979cda37e43828cd6e1787649f1d8ca8c Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Tue, 22 Feb 2011 18:07:57 -0500 Subject: add support for checking if an ERL_NIF_TERM is an exception Add the enif_is_exception function to allow callers to determine whether an ERL_NIF_TERM represents an exception. (Currently the only supported exception is badarg since only enif_make_badarg exists, but this will likely be expanded in future releases.) This allows NIF code to call other NIF functions that return ERL_NIF_TERM and properly check to see if the returned terms are exceptions. Without the enif_is_exception function, developers have to create their own means of checking whether a function creates an exception, such as returning boolean success/failure indicators or some other special value indicating that an exception is in effect. The declaration of enif_is_exception in erl_nif_api_funcs.h respects the order of declarations required to keep compatibility on Windows. Add a new test to verify the operation of enif_is_exception. Modify the erl_nif man page to add a description of enif_is_exception and also to clarify the requirements of calling the enif_make_badarg function. If code calls enif_make_badarg, the env passed in gets set with exception information and so the return value of the calling function MUST be the badarg term returned from enif_make_badarg. Also clarify that the result of enif_make_badarg may be passed only to enif_is_exception and not to any other NIF API functions. --- erts/doc/src/erl_nif.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'erts/doc') diff --git a/erts/doc/src/erl_nif.xml b/erts/doc/src/erl_nif.xml index 4bbd4e2a54..cdce4ec0b8 100644 --- a/erts/doc/src/erl_nif.xml +++ b/erts/doc/src/erl_nif.xml @@ -688,6 +688,10 @@ typedef enum { Determine if a term is an empty list

Return true if term is an empty list.

+ intenif_is_exception(ErlNifEnv* env, ERL_NIF_TERM term) + Determine if a term is an exception +

Return true if term is an exception.

+
intenif_is_fun(ErlNifEnv* env, ERL_NIF_TERM term) Determine if a term is a fun

Return true if term is a fun.

@@ -738,7 +742,14 @@ typedef enum {
ERL_NIF_TERMenif_make_badarg(ErlNifEnv* env) Make a badarg exception. -

Make a badarg exception to be returned from a NIF.

+

Make a badarg exception to be returned from a NIF, and set + an associated exception reason in env. If + enif_make_badarg is called, the term it returns must + be returned from the function that called it. No other return value + is allowed. Also, the term returned from enif_make_badarg may + be passed only to + enif_is_exception and + not to any other NIF API function.

ERL_NIF_TERMenif_make_binary(ErlNifEnv* env, ErlNifBinary* bin) Make a binary term. -- cgit v1.2.3