I have seen a few examples like this, this and this, which show how to throw custom exception in Python. But what I'm hoping to accomplish is something like this:
## in main.py
import my_errors
if os.path.exists(filename):
# here, I'd like to pass in 'filename' as parameter to FileNotFound
raise my_errors.FileNotFound(filename)
## in my_errors.py
class MyError(Exception):
pass
class FileNotFound(MyError):
# here, how do I make this FileNotFound class to accept/receive 'filename' as parameter so that I can print something informative like below
print("FileNotFound ERROR: Please make sure that the following file exists:", filename)
Thank you in advance for your help!