[Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

Kent Johnson kent37 at tds.net
Sun Feb 14 14:25:10 CET 2010


On Sun, Feb 14, 2010 at 6:33 AM, patrice laporte <zepangolin at gmail.com> wrote:

> - try/catch open(this_file_name) and if I got an IOErro exception, I
> re-raise my own exception with :
>    - the name of the class where that IOError occured
>    - the name of the method in that class that make that error occured
>    - the name of the file the method tried to opened
>    - some other info to help diagnostic
>
> Then my exception object can :
>    - log in a file dedicated to the team (so, just me for the moment)
>    - and/or log in a file dedicated to the user
>
> And then the app can popup a message box or something like that.

For simple applications that run from the command line and just do one
thing, it is often adequate to let the exceptions propagate to the top
level of the program and abort it, printing the stack trace.

If the programming is doing some kind of repeated processing and you
don't want an error in one iteration to abort the rest of the
processing, then catch the exception inthe loop and log the error,
then continue.

The logging module makes it pretty easy to log exceptions. You can
even have it log a detailed error to a file and a shortened version to
the console.

For GUI programs I usually install an exception handler in the event
loop so if there is a problem running any event the error is caught
and logged and the program continues.

Kent


More information about the Tutor mailing list