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

No, defer is always optional, which makes it highly error prone.

There's errdefer, which only defers if there was an error, but presumably you meant what you wrote, and not that.

BTW, D was the first language to have defer, invented by Andrei Alexandrescu who urged Walter Bright to add it to D 2.0 ... in D it's spelled scope(exit) = defer, scope(failure) = errdefer, and scope(success) which is only run if no error.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: