<div dir="ltr">I am trying to write a dirty nif and am following the directions from <a href="http://www.erlang.org/doc/man/erl_nif.html">http://www.erlang.org/doc/man/erl_nif.html</a><br><div><br>Exceprt:<br>"A dirty NIF may not invoke the <span class=""><a href="http://www.erlang.org/doc/man/erl_nif.html#enif_make_badarg">enif_make_badarg</a></span>
to raise an exception. If it wishes to return an exception, the dirty NIF should pass a
regular result indicating the exception details to its finalizer, and allow the finalizer
to raise the exception on its behalf."<br><br></div><div>So I am doing this; here is my finalizer.... <br><br><br><span style="font-family:courier new,monospace"><font size="1">// cached atoms<br>ERL_NIF_TERM badarg;<br>
<br>static ERL_NIF_TERM badarg_finalizer(ErlNifEnv* env, ERL_NIF_TERM term)<br>{<br> if(term == badarg) <br> return enif_make_badarg(env);<br> else<br> return term;<br>}</font><br></span><br></div><div>
... and I end up with the exception context of the finalizer and not the nif as desired...<br><br><br><span style="font-family:courier new,monospace"><font size="1">5> generate_rsa:generate_rsa_key(abc, 65537).<br>entering generate_rsa_key_nif<br>
entering generate_rsa_key_nif_dirty<br> entering badarg_finalizer<br> ** exception error: bad argument<br>
in function generate_rsa:generate_rsa_key_nif/2<br> called as generate_rsa:generate_rsa_key_nif(badarg,18446744072346624528) <b>!!! should be (abc,65537)</b><br> in call from generate_rsa:generate_rsa_key/2 (src/generate_rsa.erl, line 25)</font></span><br>
<br><br></div><div>The documentation implies I can provide the "exception details", but enif_make_badarg() doesn't offer any extra parameters. Is there some other way to set the "exception details"?<br>
<br></div><div>Thanks,<br>Dan.<br></div></div>