Don’t use exceptions for flow control.

That’s not what they’re for.

An exception should represent unexpected behavior. It should be something like an error condition, a fault, or something seriously broken.

Use other structures for standard flow control. Try the “if” statement, or a “case” statement, or polymorphism.

Exceptions act like GOTO statements and make spaghetti code that is hard to follow. Don’t make life hard on yourself. Don’t make things difficult for the people who come after you and have to maintain your code. Avoid using exceptions for flow control.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: