Code Smell 73 — Exceptions for Expected Cases
Exceptions are handy Gotos and flags. Let’s abuse them.

TL;DR: Do not use exceptions for flow control.
Problems
Readability
Principle of least astonishment Violation.
Solutions
1. Use Exceptions just for unexpected situations.
2. Exceptions handle contract violations. Read the contract.
Sample Code
Wrong
Right
Detection
This is a semantic smell. Unless we use machine learning linters it will be very difficult to find the mistakes.
Tags
Readability
Conclusion
Exceptions are handy, and we should definitively use them instead of returning codes.
The boundary between correct usage and wrong usage is blur like so many design principles.
Relations
Code Smell 72 — Return Codes
blog.devgenius.io
Code Smell 26 — Exceptions Polluting
It is very nice to have lots of different exceptions. Your code is declarative and robust. Or not?blog.devgenius.io
More info
https://wiki.c2.com/?DontUseExceptionsForFlowControl
Why You Should Avoid Using Exceptions as the Control Flow in Java - DZone Java
Learn more about using exceptions as control flow in Java. Java is a general-purpose programming language with many…dzone.com
Are exceptions as control flow considered a serious antipattern? If so, Why?
I think the easiest way to answer this is to understand the progress OOP has made over the years. Everything done in…softwareengineering.stackexchange.com
Why not use exceptions as regular flow of control?
To avoid all standard-answers I could have Googled on, I will provide an example you all can attack at will. C# and…stackoverflow.com
When debugging, novices insert corrective code; experts remove defective code.
Richard Pattis
Software Engineering Great Quotes
Sometimes a short thought can bring amazing ideas.blog.devgenius.io
This article is part of the CodeSmell Series.
How to Find the Stinky parts of your Code
The code smells bad. Let’s see how to change the aromas.blog.devgenius.io

