tfrederiksen / inelastica

Python package for eigenchannels, vibrations and inelastic electron transport based on SIESTA/TranSIESTA DFT
https://tfrederiksen.github.io/inelastica
GNU Lesser General Public License v3.0
33 stars 16 forks source link

Implement raise errors instead of sys.exit #38

Open tfrederiksen opened 6 years ago

tfrederiksen commented 6 years ago

Many places we use sys.exit(...) or simply kuk (the lazy, Swedish version) to abort execution.

Nick suggests that it is clearer to raise errors since Python scripts can then continue (if needed).

zerothi commented 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:

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.

tfrederiksen commented 6 years ago

Thanks Nick. I will try to implement this.