3 ms·
You know how GOTO is real bad? Well, using exceptions for flow control* is basically a thinly disguised GOTO. Also, constructing an exception object, with the
by piaste 10y ago
You know how GOTO is real bad? Well, using exceptions for flow control* is basically a thinly disguised GOTO.
Also, constructing an exception object, with the full stacktrace etc., is a pretty heavy operation and can cause big performance issues. But it's mostly the first thing.
* Which is an important distinction. Flow control exception are recognisable because you intentionally throw an exception and expect it to be caught by a particular catcher to process it in a particular way - much like a GOTO, and with all its fragility. In the proper usage of exceptions, when you throw an exception you don't care which line of code catches it and when you catch an exception you don't care which line of code threw it.
- nerdponx 10y agoBelieve it or not, I was just working on a script this weekend that was becoming a nightmare to debug. And when I realized that I had been lazily using exceptions as control flow, this really hit home.