Skip to content
Advertisement

How can I write a `try`/`except` block that catches all exceptions?

How can I write a try/except block that catches all exceptions?

Advertisement

Answer

You can but you probably shouldn’t:

JavaScript

However, this will also catch exceptions like KeyboardInterrupt and you usually don’t want that, do you? Unless you re-raise the exception right away – see the following example from the docs:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement