Robust exception handling - Eli Bendersky's website
Exceptions are better than returning error status codes. Some languages (like Python) leave you with no choice but to handle exceptions, as the whole language core and standard libraries throw them. But even in languages where this is not so, you should prefer exceptions to error codes. In the Python world this is sometimes called the EAFP (Easier to Ask for Forgiveness than Permission) versus LBYL (Look Before You Leap) debate. To quote Alex Martelli1 (because I couldn't have said it better myself): A common idiom in other languages, sometimes known as "look before you leap" (LBYL), is to check in advance, before attempting an operation, for all circumstances that might make the operation invalid. This approach is not ideal for several reasons: 1. The checks may diminish the readability and clarity of the common, mainstream cases where everything is okay. 2. The work needed for checking may duplicate a substantial part of the work done in the operation itself. 3. The programmer might
Executive introduction Exceptions are important This article is mainly intended for my own consumption, so take it with a grain of salt The examples are in Python, but the ideas apply to most languages Exceptions vs. error status codes Exceptions are better than returning error status codes. Some languages (like Python) leave you with no choice but to handle exceptions, as the whole language core and standard libraries throw them. But even in languages where this is not so, you should prefer exceptions to error codes. In the Python world this is sometimes called the EAFP (Easier to Ask for For
Explore this link on the map →related reading
- 22. Exception - CS2030S Programming Methodology IInus-cs2030s.github.io
- Rust Solves The Issues With Exceptions · Dmitrii Aleksandrovhome.expurple.me
- Exception and error handling | Kotlin Documentationkotlinlang.org
- Getting Started: Error Handling | Next.jsnextjs.org
- Google Testing Blog: Code Health: Reduce Nesting, Reduce Complexitytesting.googleblog.com
- Modular Errors in Rust - Sabrina Jewsonsabrinajewson.org
- styleguide | Style guides for Google-originated open-source projectsgoogle.github.io
- Error Boundaries in React - Handling Errors Gracefully | Refinerefine.dev
- Would you fly on an AI-coded plane | Hackle's bloghacklewayne.com
- Recoverable Errors with Result - The Rust Programming Languagedoc.rust-lang.org
- TypeScript Structured Concurrencythecandidstartup.org
- Error Handling in Rust - Andrew Gallant's Blogburntsushi.net