Re-raising a RuntimeError - good practice?

Andrew Berg robotsondrugs at gmail.com
Thu Oct 24 21:17:24 EDT 2013


On 2013.10.24 20:09, Victor Hooi wrote:
> Also, @Andrew Berg - you mentioned I'm just swallowing the original exception and re-raising a new RuntimeError - I'm guessing this is a bad practice, right? If I use just "raise"
> 
>         except Exception as err:  # catch *everything* 
>             logger.error(err) 
>             raise 
> 
> that will just re-raise the original exception right?
Yes. However, if you are doing logging higher up where you actually handle the exception, then logging here is redundant, and you can simply
eliminate the try/catch block completely.

-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 10.0



More information about the Python-list mailing list