Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Cute example but what exactly does your handle_file_not_found() function do? Isn't it the caller further up the stack that knows best what to do? Assuming your example code is inside library_function_foo() and I'm a web server calling into library_function_foo() i know i should return http code 500 if "anything" throws an exception, if i reuse library_function_foo() in another command-line client project i might want it to print the error message to stdout instead.


> Isn't it the caller further up the stack that knows best what to do?

Often yes (one of the exceptions being a simple die() routine that cleans up only global state). It's just pseudocode, and in real code you will often not call any functions in the exception handling block.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: