How to reduce the repetitious code in create mnesia table?

钱晓明 <>
Tue Mar 30 09:09:20 CEST 2010


Hi, I want to create many tables in mnesia, but I find the code is very long
if check the return value of mnesia:create_table every time:

case mnesia:create_table(ig_master, [{attributes, record_info(fields,
ig_master)}]) of
    {aborted, Reason} ->
         error_logger:error_msg("Fail to create table ~p: ~p!", [ig_master,
Reason]),
         throw({error, create_table});
    {atomic, ok} ->
         ok
 end,
%% repetitious code to create other 6 tables.

Is there any way I can do to reduce the repetitious code? I have
tried defining a new function accepting the name of record to do the same
thing above, but can not compile code because of record_info.

By the way, I do not find the way to leave a function except using
throw/exit. Is there any way I can use to just leave current function,
replace the "throw" statement above?

Thanks!


More information about the erlang-questions mailing list