0

I want to catch an exception thrown from imported module and raise it to fail the job giving the same exception.

for example,

------a.py----------

def check(a, b):
    try:
        # Check something
    except Exception as e:
        raise Exception(f"Exception is {e}")
-------b.py-------
import a

def function():
    try:
        res = a.check()
    except Exception as e:
        raise e

In the above example if check function raises an error, I want to catch it in b.py file and raise it thus stopping the execution. I am able to get the exception but the execution does not stop, it continues running b.py file. I even tried sys.exit(1) after catching the exception.

Any suggestions?

Tushar Patil
  • 748
  • 4
  • 13
  • does this help https://stackoverflow.com/questions/34622668/catching-exception-from-a-called-function – Abhishek Jul 15 '22 at 10:03
  • No, I checked it out, it doesn't work in my case, it just catches the exception and continues, but I want to throw that error and stop the execution – Tushar Patil Jul 15 '22 at 10:07

0 Answers0