Question

If I have a function returning an Either such as GetUserFromDb(int id) and the database is offline should I catch the error in the function and wrap it in a failure / Left case or should I let it bubble out as an exception as there is nothing I can do and it really is an exceptional situation.

Comments / Suggestions welcome.

Cheers,

Blair

No correct solution

OTHER TIPS

Wrap the error in the left case. Then you need to handle it explicitly. You can "bubble out" the left case to the point where you want to handle the error, for example with an error message or log entry. I guess you don't want to crash your app if the database is offline but shut it down gracefully and inform some user about the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top