Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement raise errors instead of sys.exit #38

Open
tfrederiksen opened this issue Mar 8, 2018 · 2 comments
Open

Implement raise errors instead of sys.exit #38

tfrederiksen opened this issue Mar 8, 2018 · 2 comments
Assignees

Comments

@tfrederiksen
Copy link
Owner

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
Copy link
Collaborator

zerothi commented Mar 8, 2018

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')

Something like this.

@tfrederiksen
Copy link
Owner Author

Thanks Nick. I will try to implement this.

@tfrederiksen tfrederiksen self-assigned this Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants