Skip to content

Custom exception types could be useful #62

Description

@bmillwood

Ideally, users of the code would never want to read the string inside an exception to find out information about it: that's only useful for showing to humans. So whenever we throw a userError, we're kind of saying "the program has no useful information to give you about what error just happened". I think often this is not the case, and we should either use existing error types more effectively, or create some of our own.

Activity

  1. tibbe commented on Oct 1, 2012

    @tibbe
    Contributor

    I agree. I've had thought about creating a SocketError type in the past. It might be worth looking at the thoughts the Python people have when they recently redesigned part of the their hierarchy (http://www.python.org/dev/peps/pep-3151/).

  2. singpolyma commented on Nov 29, 2012

    @singpolyma
    Contributor

    Custom exceptions make error handling much messier. Suggest using Either where appropriate.

  3. tibbe commented on Nov 29, 2012

    @tibbe
    Contributor

    @singpolyma We're talking about replacing the current exceptions with more specific ones, so they can be caught, not changing the API to return an error code instead.

  4. singpolyma commented on Nov 29, 2012

    @singpolyma
    Contributor

    @tibbe but custom exception types make exception handling harder (cannot just catch IOException / IOError, and do not want to catch SomeException because it encompasses many should-not-catch and asynchronous exceptions).

  5. bmillwood commented on Nov 30, 2012

    @bmillwood
    ContributorAuthor

    Possibly it's reasonable to object that you can no longer catch just one exception, but I don't think that's usually what you want to do, anyway - you want to catch a specific error and respond appropriately.

    We could always provide a helper function that caught both IO and socket errors and handled them the same way.

  6. singpolyma commented on Nov 30, 2012

    @singpolyma
    Contributor

    @benmachine I try to catch all reasonable exceptions all the time, so that I can handle them in EitherT.

    Such a helper function sounds like it might solve the issue.

  7. kazu-yamamoto commented on Dec 28, 2017

    @kazu-yamamoto
    Collaborator

    Close this in favor of #151.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions