3 ms·
I see two major use cases for exceptions in C++. The first, is for errors during recursive functions. Very challenging to escape from 13 levels deep into a rec
by byuu 13y ago
I see two major use cases for exceptions in C++.
The first, is for errors during recursive functions. Very challenging to escape from 13 levels deep into a recursive descent parser without throw.
The second, is for container access-by-reference functions that are called on empty or out-of-bounds elements (eg array(4); array[16] = value;), since otherwise there is no way to return from the function, as you may not know how to construct a new container element (eg no default constructor), nor would you necessarily want to return a dummy object in that case.