Proper way to handle errors in a module

Andrew Berg bahamutzero8825 at gmail.com
Wed May 11 14:14:39 EDT 2011


On 2011.05.11 12:57 PM, Patty wrote:
> Hi Andrew -
>
> Sometimes you want an exception come up and then use that information to 
> take your
> program in some direction.
Right, but I'm wondering how I should handle errors in a module, where
different people will want their programs to do different things when an
error occurs in a function or method from my module (which is not
necessarily because of a bug in my module - the calling script could
send a bad parameter or some system configuration could prevent the
function from doing something). On one hand, I could let almost all
exceptions go unhandled and have the calling script handle them. This
would force the developer of the calling script to learn all the
exceptions that my module could raise (which could be really annoying if
I have custom exceptions for problems that don't otherwise raise an
exception). OTOH, I could handle all the exceptions and return None or
some default value, but that would make it harder for the developer to
make the script react appropriately.



More information about the Python-list mailing list