Hacker News new | past | comments | ask | show | jobs | submit login

Maybe there is a nuance that I am missing, but having in mind that an exception can be thrown "in any of your code, regardless of whether it could have possibly raised an exception before" when writing code seems sane to me. It seems like the issue being raised is that people are expecting code snippets to be perfectly transactional, which also seems wrong.



Yes. This is why you should always use context managers and finally blocks in languages with exceptions. Always assume that anything can fail at any time and accept that not everything can nor should be recovered from.

On the other end of the spectrum you have go, where in fact every line does need to have their error conditions explicitly checked. How do they handle this situation?

What is dangerous with finally-blocks is if they start consuming a lot of time, such that the timeout interruption itself makes the timeout miss its deadline. Usually you need 2 timeouts, one for the main operation and a second for the cleanup.




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

Search: