dune
dune copied to clipboard
Error handling
When I'm not connected to the internet, curl fails to get weather data which causes parse@json to fail, and also terminates the execution of my prelude early. I think that we should try to make a convenient way to handle errors (although the parsing functions should be implemented such that they return None instead of throwing errors).
I'm thinking of implementing a try builtin function that might behave like the following:
try 2 // 0 { echo "divide by zero"; 0 }
try would attempt to evaluate the first argument If it does not throw an error, then try will return that result. If the first argument fails to evaluate, it would evaluate the second argument, and return its result.
I'd prefer a syntax where the exception is available as a variable, for example:
try 2 // 0
catch e -> { echo e@message; 0 }