Is it OK to raise a built-in exception, but with a different message, in Python? -
Is it custom to enhance custom text? Or to take a single with custom text?
The document reads:
Exception value error: Arises when an underlying operation or function receives an argument (...)
Is it contained that only should the underlying operations take a ValueError exception?
In practice, I understand that it is safe to make exception class which is received by the error or exception but it is fine to do this, and directly to a value error ("custom Text ")?
As ValueError is built, by lifting a ValueError (with a custom text), users can quickly see whether the comparison of a custom exception type (like "ValueErrorSpecificModule", which is not standard) Includes the kind of problem.
increase ValueError ("invalid input encoding")
In fact, I do a lot of things often when I'm writing passes before some code. The main problem in doing this in such a way is that there is a hard time with the exception of your code client; In order to catch that specific exception, they must match the string on the exception object caught, which is clearly weak and tedious, thus implementing a ValueError subclass of your own would be better; It can still be caught as ValueError, but also as a more specific exception class.
A common rule of thumb is that whenever you have the code:
increase the valueValueError (some problem:% s'% value)
/>You should change it like something:
class SomeProblem (ValueError): "" "to indicate a problem with the specified value." Increase some excite (value) You can say that the exception type specifies what went wrong, while the message / attributes how this has gone wrong < / Div> no The Rdisht.
Comments
Post a Comment