Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57501

Re: Re-raising a RuntimeError - good practice?

Newsgroups comp.lang.python
Date 2013-10-25 00:44 -0700
References <670cb7a6-f8e9-4e3d-95a0-95728f8dd815@googlegroups.com>
Message-ID <1577ebdb-8e31-4b68-9ae4-e9b08d2d9d74@googlegroups.com> (permalink)
Subject Re: Re-raising a RuntimeError - good practice?
From Peter Cacioppi <peter.cacioppi@gmail.com>

Show all headers | View raw


I'm surprised no-one is mentioning what seems the obvious pattern here - exception wrapping.

So you define your exception class as containing the root exception.

Then your specific job routines wrap the exceptions they encounter in your personal exception class. This is where you go add in specific information re: the circumstances under which the exception occurred. 

Then you throw your exception, which is captured at the appropriate level, and logged appropriately.

The nice thing here is that you to tend to write all the exception logging in one place, instead of scattered all around.

Your code looks very close to this pattern.  Just raise an exception that can wrap the low level exception.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re-raising a RuntimeError - good practice? Victor Hooi <victorhooi@gmail.com> - 2013-10-23 20:23 -0700
  Re: Re-raising a RuntimeError - good practice? Steven D'Aprano <steve@pearwood.info> - 2013-10-24 04:34 +0000
  Re: Re-raising a RuntimeError - good practice? Andrew Berg <robotsondrugs@gmail.com> - 2013-10-23 23:42 -0500
    Re: Re-raising a RuntimeError - good practice? Victor Hooi <victorhooi@gmail.com> - 2013-10-24 18:09 -0700
      Re: Re-raising a RuntimeError - good practice? Andrew Berg <robotsondrugs@gmail.com> - 2013-10-24 20:17 -0500
        Re: Re-raising a RuntimeError - good practice? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-25 02:30 +0000
  Re: Re-raising a RuntimeError - good practice? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-25 00:44 -0700

csiph-web