How to handle exceptions properly in a pythonic way?

zljubisic at gmail.com zljubisic at gmail.com
Wed Nov 4 22:41:38 EST 2015


> The best way is probably to do nothing at all, and let the caller handle
> any exceptions.

In that case every call of the get_html function has to be in the try/except block with many exceptions.
Sometimes, it is enough just to know whether I managed to get the html or not.
In that case, I could for example, in get_html have try/except block which will as result raise let's say NoHtml custom exception or return some special value.

Raising an exception forces me to put every call of the get_html function in try/except block.
If I am returning a special value, than I can call get_html and then test the value.

I am not sure which approach is better.




More information about the Python-list mailing list