Open tfrederiksen opened 6 years ago
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
:
ValueError
is raisedNotImplementedError
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')
Something like this.
Thanks Nick. I will try to implement this.
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).