error handling in functional way