<div dir="ltr">In some of the code I've written, I opted to check for bad arguments before scheduling the job on the dirty scheduler. This means that you don't move the call to the dirty scheduler unless you know it will run. But I like Steve's suggestion to check as much as possible in the Erlang VM as well.</div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 28, 2014 at 10:51 PM, Daniel Goertzen <span dir="ltr"><<a href="mailto:daniel.goertzen@gmail.com" target="_blank">daniel.goertzen@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thanks, that's what I will do then.<br><br></div>PS, the dirty schedulers are working very well for me.  I ran a cpu-bound nif that took about an hour, and the rest of the Erlang system just kept on ticking.<br>



</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 28, 2014 at 2:46 PM, Steve Vinoski <span dir="ltr"><<a href="mailto:vinoski@ieee.org" target="_blank">vinoski@ieee.org</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Wed, May 28, 2014 at 3:19 PM, Daniel Goertzen <span dir="ltr"><<a href="mailto:daniel.goertzen@gmail.com" target="_blank">daniel.goertzen@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">http://www.erlang.org/doc/man/erl_nif.html</a><br>



<div><br>Exceprt:<br>"A dirty NIF may not invoke the <span><a href="http://www.erlang.org/doc/man/erl_nif.html#enif_make_badarg" target="_blank">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"?</div>



</div></blockquote><div><br></div></div></div><div>"Exception details" here is just general, meaning whatever kinds of error information you want the finalizer to return. A NIF can raise only badarg via enif_make_badarg(), and there's no way for it to control any parameters associated with the exception. You might instead consider wrapping the NIF function with an actual Erlang function in your module, treating the NIF like an internal (non-exported) function, having the finalizer return an error tuple containing relevant information, and letting Erlang raise an exception based on that info.</div>


<span><font color="#888888">
<div><br></div><div>--steve</div></font></span></div></div></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>J.
</div>