Content deleted Content added
Line 222:
The [[Go (programming language)#Omissions|Go]] developers believe that the try-catch-finally idiom obfuscates [[control flow]],<ref>{{cite web |url=https://golang.org/doc/faq#exceptions |title=Frequently Asked Questions |access-date=2017-04-27 |quote=We believe that coupling exceptions to a control structure, as in the try-catch-finally idiom, results in convoluted code. It also tends to encourage programmers to label too many ordinary errors, such as failing to open a file, as exceptional. |url-status=live |archive-url=https://web.archive.org/web/20170503205801/https://golang.org/doc/faq#exceptions |archive-date=2017-05-03 }}</ref> and introduced the exception-like {{code|lang=go|panic}}/{{code|lang=go|recover}} mechanism.<ref>[https://code.google.com/p/go-wiki/wiki/PanicAndRecover Panic And Recover] {{webarchive|url=https://web.archive.org/web/20131024144034/https://code.google.com/p/go-wiki/wiki/PanicAndRecover |date=2013-10-24 }}, Go wiki</ref> {{code|lang=go|recover()}} differs from {{code|catch}} in that it can only be called from within a {{code|lang=go|defer}} code block in a function, so the handler can only do clean-up and change the function's return values, and cannot return control to an arbitrary point within the function.<ref>{{cite web |last1=Bendersky |first1=Eli |title=On the uses and misuses of panics in Go |url=https://eli.thegreenplace.net/2018/on-the-uses-and-misuses-of-panics-in-go/ |website=Eli Bendersky's website |access-date=5 January 2022 |date=8 August 2018|quote=The specific limitation is that recover can only be called in a defer code block, which cannot return control to an arbitrary point, but can only do clean-ups and tweak the function's return values. }}</ref> The {{code|lang=go|defer}} block itself functions similarly to a {{code|finally}} clause.
The [[Rust (programming language)|Rust]] language does not have exceptions. It instead uses <code>Result<T, E></code> (a [[result type]]) for handling errors.
==See also==
|