I am a newbie and have a question related to error handling in django/python; hoping the pros can provide some directions.

In my project, I am sometimes using try/except and other places checking for errors returned from functions. Mostly, all API calls have try/except and then general error handling otherwise. As the project has grown in size, it is becoming quite unwieldy and now it is very hard to ensure that all errors are being properly handled. Especially, with multiple levels of nested functions, it is hard to make sure that I am checking for errors from each function, propagating it properly upstream and handling at every level.

I have so far ensured that all APIs have try/except. And I am also checking each function for error handling. My simple question is –

  1. is there a defined or recommended way to handle errors?
  2. is it possible to really end the program and gracefully exit (after logging the error + stack trace in the log file) in case of certain errors? This is because even if I am handling the error in the function and returning appropriate value, I don’t want to rely on the upstream functions properly handling/propagating the error?

Happy for someone to point me to any authoritative source that I can read and follow? My simple search over the past several days have not yielded one for me.

Thanks in advance!