[erlang-questions] is empty catch statement possible?

Konstantin Tcepliaev f355@REDACTED
Fri Feb 10 08:17:47 CET 2012


Hello again, Motiejus.

One more thing: macro variables' scope is not limited to the text of macro, so in a piece of code such as:

lager:set_loglevel(lager_console_backend, InitialLevel),
..
?silent(SLevel, Expr),
..
lager:set_loglevel(lager_console_backend, NewLevel), %% NewLevel /= InitialLevel
..
?silent(SLevel, OtherExpr), %% badmatch here!

..you'll get a badmatch error on your __Lager_OldLevel variable. Redefining your macro as a normal function would be a great solution.

09.02.2012, 23:18, "Motiejus Jakštys" <desired.mta@REDACTED>:
> On Thu, Feb 09, 2012 at 11:06:56PM +0400, Konstantin Tcepliaev wrote:
>
>>  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.
>
> Yes, that was another mistake...
>
>>  2. You can omit 'catch' clause entirely, leaving only 'try' and
>>  'after'.
>
> Cool. Not sure why didn't work before, when I tried that.
>
>>  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.
>
> Didn't know it's possible to do like that. Thanks!
>
> Motiejus

Regards,
-- 
Konstantin



More information about the erlang-questions mailing list