[erlang-questions] Raising arbitrary exceptions from NIFs
Masatake Daimon
daimon@REDACTED
Wed Nov 9 02:59:54 CET 2011
Hello,
I have a proposal for additional functions to erl_nif. Currently the
only exception that NIFs can raise is 'badarg', which is rather
inconvenient as it doesn't carry any useful information about the
specific cause of problem. I want to raise not only 'badarg' but
arbitrary exceptions from NIFs.
> ERL_NIF_TERM enif_make_error(ErlNifEnv* env,
> ERL_NIF_TERM reason,
> unsigned argc,
> const ERL_NIF_TERM argv[]);
>
> Make an error exception to be returned from a NIF, and set an
> associated exception 'reason' and an optional argument list in
> 'env', just like erlang:error/2. If enif_make_error is called, the
> term it returns is subject to the same limitation of
> enif_make_badarg's return value.
>
>
> ERL_NIF_TERM enif_make_exit(ErlNifEnv* env, ERL_NIF_TERM reason);
>
> Make an exit exception to be returned from a NIF, and set an
> associated exception 'reason' in 'env', just like erlang:exit/1. If
> enif_make_exit is called, the term it returns is subject to the same
> limitation of enif_make_badarg's return value.
>
>
> ERL_NIF_TERM enif_make_throw(ErlNifEnv* env, ERL_NIF_TERM any);
>
> Make a throw exception to be returned from a NIF, and set an
> associated exception reason 'any' in 'env', just like
> erlang:throw/1. If enif_make_throw is called, the term it returns is
> subject to the same limitation of enif_make_badarg's return value.
I know I should submit an EEP for this, but since that means I have to
provide a reference implementation, submitting EEP is a lot of load
for me. Any comments or suggestions on this proposal are highly
welcomed.
Thanks,
Masatake Daimon
--
大門 正岳 <daimon@REDACTED>
More information about the erlang-questions
mailing list