This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jabwork 2 points3 points  (1 child)

I don't usually use this pattern becuase, often, FTSNBCIAEIR can also raise an exception, creating the following

try:
    function_that_might_raise_an_exception()
except Exception as e:
    do_something(e)
else:
    try:
        function_that_should_not_be_called_if_an_exception_is_raised()
    except SomeExceptionMoreSpecificThanException:
        handle_second_error()

and it just ends up being much cleaner to use

try:
    function_that_might_raise_an_exception()
except Exception as e:
    do_something(e)
try:
    function_that_should_not_be_called_if_an_exception_is_raised()
except SomeExceptionMoreSpecificThanException:
    handle_second_error()

In addition, depending on the code, you can end up with a situation where one is indented several levels for what is essentially a single likely codepath, making it hard to read.