Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why passing exception as e doesn't work, while explicitely does?

I’m catching an exception and I want to pass it further. I’ve tried this the 2 following ways:

except exceptions.MyException as e:
  raise exceptions.MyException(message=e.message)

and:

except exceptions.MyException as e:
  raise e(message=e.message)

further, I catch it as this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

except ArticleNotAcceptable as e:
  Messages.flash(e.message)

While the first version works fine, the second doesn’t – it causes 'NoneType' object has no attribute 'id' that doesn’t tell me much. Can anyone please explain to me why?

>Solution :

exceptions.MyException is a class. e is an instance of MyException. You can call the class to get another instance of MyException. You cannot call an instance to get another instance.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading