[erlang-questions] is empty catch statement possible?

Konstantin Tcepliaev f355@REDACTED
Thu Feb 9 20:06:56 CET 2012

Hello, Motiejus.

1. Yes, except that your code will return your Expr wrapped in zero arity fun, which is probably not what you want, though I'm not sure.
2. You can omit 'catch' clause entirely, leaving only 'try' and 'after'.

Also a couple of tedious notes: first, better be less javascriptish and replace your outer lambda with begin ... end, as that'll be a bit faster and a lot more readable, and second - avoid starting variable name with underscore when you're going to use its value somewhere, it'll save you from stupid debugging someday.

09.02.2012, 22:37, "Motiejus Jakštys" <desired.mta@REDACTED>:

>  Hello,
>  consider this macro:
>  -define(silent(Level, Expr), (fun() ->
>                  __Lager_OldLevel = lager:get_loglevel(lager_console_backend),
>                  try
>                      fun() -> Expr end
>                  catch
>                      throw:'$__should_never_be_thrown' -> ok
>                  after
>                      leger:set_loglevel(lager_console_backend, __Lager_OldLevel)
>                  end
>          end)()).
>  1) does it do what I expect? I want log level to be restored in _any_ case.
>  2) Is there a way to avoid the stub throw:Atom statement?
>  Thanks
>  Motiejus
>  _______________________________________________
>  erlang-questions mailing list
>  erlang-questions@REDACTED
>  http://erlang.org/mailman/listinfo/erlang-questions


More information about the erlang-questions mailing list