Look on try command.<br><br><div class="gmail_quote">2008/7/11 Colin Z <<a href="mailto:theczintheroc2007@gmail.com">theczintheroc2007@gmail.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I need some advice on part of an application I'm writing.<br><br>Basically I've got a gen_server that is responsible for processing command records sent to it via casts.<br><br>It just uses an mnesia DB to map command codes to logic modules (so, it's kind of like a scripting system).<br>
<br>I'm running into problems when there's a typo in the DB (ie: the module specified in the DB doesn't actually exist) or when there's an error in the logic module. It will cause my gen_server to crash. If it crashes too often it'll bring down the application obviously.<br>
<br>handle_cast( {queue_command, ?CMD_VAR}, State ) -><br><br> Command = mnesia:dirty_read(?STATE.commandDB, list_to_atom(?CMD.command)),<br><br> case Command of<br> [] -><br> io:fwrite("Could not find command `~p`~n",[?CMD.command]),<br>
ok<br> ;<br> [#command{module=Module}] -><br> case gen_command:validate(Module, ?CMD_VAR) of<br> ok -><br> gen_command:do(Module, ?CMD_VAR),<br>
ok<br> ;<br> denied -><br> ok<br> end<br> end,<br> {noreply, State}<br>;<br><br>If it finds the command code in the DB it will call the logic module's validate() method to see if it's allowed, then calls do(). (I'm doing some magic with the macros there, but it's just convenience for working with records.)<br>
<br>The gen_command module just does this:<br><br>do(CallbackModule, ?CMD_VAR) -><br> CallbackModule:do(?CMD_VAR)<br>.<br><br><br>Should I be doing a try...catch in gen_command to keep the gen_server from crashing, or is my design just way off to begin with? Or maybe I should be letting the server crash and just change the supervision tree so it can crash as many times as it wants?<br>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil