+ 2

How can I raise user-defined exceptions in python?

Hello, I have the following code, which consists of a class "Errors" which is meant to have classmethods with user-defined errors. The code snippet was taken out of a program, however it doesn't rely on the rest of the code. When I call a class method, which raises a certain error, at the end I get "NameError" - which means that the error from a classmethod I have called does not exist - this is true indeed. I want to be able to call user-defined exceptions without a "NameError" pop up at the end. How can I do so? And do I need to inherit Exceptions class into my own class? https://code.sololearn.com/cLUvW71Xx2Gv/?ref=app

9th Apr 2023, 11:11 AM
Lamron
Lamron - avatar
4 Respuestas
9th Apr 2023, 11:19 AM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 3
That's exactly what I wanted: https://code.sololearn.com/cZvpksGD7zyO/?ref=app Used classmethods in here, but someone said to store user defined errors in a package rather than a class
9th Apr 2023, 12:56 PM
Lamron
Lamron - avatar
+ 2
I was on here, it's not exactly what I want , thanks for answering though
9th Apr 2023, 11:21 AM
Lamron
Lamron - avatar
+ 1
Jay Matthews thanks. now I see what I need to do, although syntax is a bit scary 😅
9th Apr 2023, 12:02 PM
Lamron
Lamron - avatar