2 ms·
This is close to how Go handles exceptions. The 'defer' statement schedules a function to be executed at the end of the current function, no matter now the curr
by huggah 14y ago
This is close to how Go handles exceptions. The 'defer' statement schedules a function to be executed at the end of the current function, no matter now the current function is exited. The recover() call returns an active panic (panic being Go for exception)---it is only useful inside a deferred function.
See a fuller and better explanation at http://blog.golang.org/2010/08/defer-panic-and-recover.html http://blog.golang.org/2010/08/defer-panic-and-recover.html
- pcwalton 14y agoNo, it's not. Go handles errors via exceptions (which Go calls panic and recover) and return codes (and "defer" is just "finally"). In other words, Go has a mix of C-style and Java-style error handling; it doesn't have any more features than either of them. (This is of course totally fine; Java's exception system is not a bad exception system.) What the post is asking for is more like Common Lisp's condition system.
- huggah 14y ago> Whenever an exception happens, programmers could twiddle a few variables and set the program back to where it was before. This is missing. The first point of the OP is entirely as described though.