3 ms·
Even with RAII in C++, goto is still useful for handling the occasional error case where you need to reset/retry some operation e.g. due to transient hardware i
by jandrewrogers 4y ago
Even with RAII in C++, goto is still useful for handling the occasional error case where you need to reset/retry some operation e.g. due to transient hardware issues that are not unrecoverable errors. A common example that comes to mind immediately is asynchronous disk reads where the data was corrupted during transfer but may succeed if transparently cleaned up and re-issued.
I use goto rarely. But there are times when anything else would be inelegant, and in those instances I'll use it without hesitation.
- rightbyte 4y agoGotos are quite nice for some state machines too. You essentially store the state in the instruction pointer instead of some helper variable.