0

I know that you can use try and except to specifically try a block of code, but I want to know if there is a way where you can fire a function when there is an error during runtime (think something like printing something letting the user know that there was an error).

martineau
  • 119,623
  • 25
  • 170
  • 301
Jeweled
  • 39
  • 8
  • Marked as duplicate of a question where you can read about this in more detail, but the short of it is that exceptions are raised all the way up the call stack until caught. That means you don't need to have a `try/except` in every single function to make sure exceptions get caught; just put a `try/except` at the very top level of your program (the `__main__` block) to catch any exceptions raised by any other part of the program. – Samwise Jul 04 '21 at 22:20
  • That's what a stack trace does. Keep in mind that you can only resume your program from the point where the exception is *caught*, not where the exception is *raised*. – chepner Jul 04 '21 at 22:22

0 Answers0