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

Asynchronous exeptions #1014

Open
kazu-yamamoto opened this issue Nov 20, 2024 · 0 comments
Open

Asynchronous exeptions #1014

kazu-yamamoto opened this issue Nov 20, 2024 · 0 comments

Comments

@kazu-yamamoto
Copy link
Contributor

Rule 1: don't catch asynchronous exceptions of others

Exceptions of others have their own semantics. If you catch them, your code does not work well. For instance, if you use the async library and catch AsyncCancelled, a thread tree created by concurrently cannot be destroyed.

If you use SomeException for catch, handle or try, check if the caught exception is asynchronous. And re-throw it via throwIO if asynchrnous. You can use the following code to check asynchronous or not.

isAsyncException :: Exception e => e -> Bool
isAsyncException e =
    case fromException (toException e) of
        Just (SomeAsyncException _) -> True
        Nothing -> False

Rule2: catch the asynchronous exception which you are using

If you don't catch, the exceptions are leaked from your threads. GHC RTS catches them and displays them to sdout.

If you are using time-manager and don't want to leak TimeoutThread, catch it.

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

1 participant