Published Aug 20, 2019

The Pragmatic Programmer - How to use Exceptions

Delve into the strategic use of exceptions in programming with Joe Zack, Michael Outlaw, and Alan Underwood as they emphasize deliberate coding, clear documentation, and the transition to Kotlin, highlighting crucial error-handling strategies and avoiding programming by coincidence.
Episode Highlights
Coding Blocks logo

Popular Clips

Episode Highlights

  • Using Exceptions

    In programming, exceptions should be reserved for truly unexpected events. and discuss how exceptions are best used for unforeseen issues, like a missing critical file, rather than predictable conditions 1. Joe emphasizes the importance of not overusing exceptions for non-exceptional circumstances, as this can lead to unnecessary complexity in code 2.

    If those aren't truly important enough to crash your application, then why are you catching them in the first place?

    ---

    This approach ensures that exceptions remain a tool for handling genuine errors, rather than a catch-all for any irregularity.

       

    Error Patterns

    Error handling in programming can be approached through various patterns, including global error handlers and status codes. highlights the use of global error handlers in web applications, which log every error as a last line of defense 3. points out the pitfalls of programming by coincidence, where reliance on nested layouts can lead to unforeseen issues 4.

    The more you nest them, the more problems you have, right. It fixes your immediate problem, but there's a root level issue somewhere that you're not aware of.

    ---

    These patterns emphasize the importance of deliberate programming and understanding the underlying issues rather than relying on temporary fixes.

       

    Crashes vs State

    The debate between crashing a program versus allowing it to continue in an inconsistent state is crucial in software development. argues that it's better to crash a program than let it run with potential errors, as this prevents further complications 5. adds that inconsistent states can lead to severe issues, such as charging a customer's credit card without recording the order 5.

    It's better to crash than and be wrong.

    ---

    This perspective underscores the importance of maintaining program integrity and preventing the propagation of errors.

Related Episodes