The Pragmatic Programmer - How to use Exceptions

Topics covered
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


The Pragmatic Programmer - How to Build Pragmatic Teams
Answers 383 questionsThe Pragmatic Programmer - How to Estimate
Answers 383 questions

Errors vs Exceptions, Reddit Rebels, and the 2023 StackOverflow Survey
Answers 383 questionsThe Pragmatic Programmer - How to Generate Code
Answers 383 questionsHow to be a Programmer
Answers 383 questions

The Pragmatic Programmer - How to Debug
Answers 383 questionsThe Pragmatic Programmer - The Evils of Duplication
Answers 383 questionsHow to be an Advanced Programmer
Answers 383 questionsHow to be an Intermediate Programmer
Answers 383 questions

Ktor, Logging Ideas, and Plugin Safety
Answers 383 questions

The Pragmatic Programmer - Tracer Bullets and Prototyping
Answers 383 questions

Clean Code - How to Write Classes the Right Way
Answers 383 questionsClean Code - How to Write Amazing Functions
Answers 383 questions

Software Design Anti-patterns
Answers 383 questions

Clean Code - How to Build Maintainable Systems
Answers 383 questions
