Improve exception handler in wsgi_app method
Replace bare except clause with explicit BaseException handler for better code clarity and to avoid potential issues with sys.exc_info(). The previous code used a bare except: clause with sys.exc_info()[1] which is discouraged in Python. This change makes the exception handling more explicit by catching BaseException directly, which includes KeyboardInterrupt and SystemExit that should not be handled by the normal exception handler. Changes: - Replace bare except: with except BaseException as e: - Add explanatory comment about BaseException handling - Remove noqa: B001 comment as it's no longer needed All existing tests pass successfully.
This commit is contained in:
parent
2579ce9f18
commit
1a413a8ffe
1 changed files with 4 additions and 2 deletions
|
|
@ -1568,8 +1568,10 @@ class Flask(App):
|
|||
except Exception as e:
|
||||
error = e
|
||||
response = self.handle_exception(ctx, e)
|
||||
except: # noqa: B001
|
||||
error = sys.exc_info()[1]
|
||||
except BaseException as e:
|
||||
# Catch BaseException (KeyboardInterrupt, SystemExit, etc.)
|
||||
# that should not be handled by the exception handler
|
||||
error = e
|
||||
raise
|
||||
return response(environ, start_response)
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue