Exception handling in functional programming