Pony has a single exception value, which isn't parameterised.
Unfortunately frequently I have code which wants to throw different kinds of exception, and I need to know what they are in order to handle them properly --- for example, trivially, when halting the program it's important to give the user the right error message!
So what's the idiomatic way of doing this in Pony?
Currently the idiomatic way would be to not use errors and instead use union types of the normal return type and the error reasons. For example, if you have a function that returns
ReturnTypeand can error with eitherError1orError2, your function signature can beThe caller function must then
matchon the union to see what happened.If you want some real-world examples, the
filespackage of the standard library uses this idiom extensively.Also, for completeness, an RFC on adding typed errors is currently being discussed.