You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Raising errors are (luckily) quite easy.
However, my main problem with raising exceptions is the choice of exceptions to raise.
I try to use a few rules in sisl:
When input are passed wrong input a ValueError is raised
When you know that you want to implement a new routine later, but haven't gotten to it. raise NotImplementedError
One should probably use project dependent exceptions to make them easily distinguishable in other projects. A small snippet:
class InelasticaException(Exception):
pass
def my_routine(*args):
if args[0] is None:
raise ValueError('my_routine: first argument cannot be None')
...
def ...(...):
if ...:
raise InelasticaException('Generic Inelastica exception')
Many places we use
sys.exit(...)
or simplykuk
(the lazy, Swedish version) to abort execution.Nick suggests that it is clearer to
raise
errors since Python scripts can then continue (if needed).The text was updated successfully, but these errors were encountered: