Most people say that it is costlier to throw exceptions than just returning from a function.
In this article in part 3, author gives an example of mimicking error handling with goto
in C (example E1). Later in the same section he gives the equivalent error handling using try-catch
in C++ (example T1). I read that if-else
is replaced by goto
when translated to machine language. If it the same case with try-catch
then it would not be costlier. So what makes try-catch
flow costlier than normal control flow.