[erlang-questions] Erlang Type specifications and throw

Rudolph van Graan rvg.mailing@REDACTED
Tue Apr 2 07:22:10 CEST 2013


Hi, 

I want to write a type spec for a function that throws exceptions, something like this:

> -spec where(G :: atom()) -> pid() | throw({no_name,atom()}).

I don't want to use an exit signal, because this behaviour is intentional and the calling process will catch this and take specific action.  But I can't write this using the -spec syntax. The documentation says:

> Some functions in Erlang are not meant to return; either because they define servers or because they are used to throw exceptions as the function below:
>   my_error(Err) -> erlang:throw({error, Err}).
> For such functions we recommend the use of the special no_return() type for their "return", via a contract of the form:
> 
>   -spec my_error(term()) -> no_return().

no_return() is completely the wrong thing to use and just leaving out the throw(…) declaration is also wrong in my eyes. How do I do this?

Thanks,
Rudolph van Graan








-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130402/ec8656cf/attachment.htm>


More information about the erlang-questions mailing list