[erlang-questions] is there "return" in Erlang.

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue Mar 1 17:56:05 CET 2011


On Tue, Mar 01, 2011 at 04:12:10PM +0100, Anthony Ramine wrote:
> Le 1 mars 2011 à 16:00, Raimo Niskanen a écrit :
> 
> > And if they can throw(Anything) elaborate with:
> > 
> > judge() ->
> >    OK = make_ref(),
> >    :
> >    :
> > 		throw(OK);
> >    :
> >    :
> > 		throw(OK);
> >    :
> >    :
> >    catch
> > 	OK -> ok;
> > 	Other ->
> > 	    erlang:raise(throw, Other, erlang:get_stacktrace())
> >    end.
> > 
> > But only library code should have to be prepared for such nonsense.
> 
> Why catch something to raise it immediately afterwards?

That is a re-raise preserving original stacktrace of anything
thrown by any called functions.

You are right, it was oversmart and redundant. Well spotted.
Catching OK -> ok; only is enough. All other exceptions are automatically
re-raised as my redundant code does. So a better ending is:
    :
    :
    catch
	OK -> ok
    end.

> 
> --
> Anthony Ramine
> Dev:Extend
> http://dev-extend.eu
> 
> 
> 
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list