G
Gonçalo Rodrigues
Hi all,
I've got two somewhat general questions related to exception handling
in C++. My usual programming language is the lovely and flexible
Python, but for various reasons, including the need to interface with
third-party libraries, get extra performance, etc. I have to use C++.
Now in Python, being a dynamically typed language, everything is
pushed to the run-time. Additionaly, since the language does not
guarantee deterministic destruction of objects, there are try/finally
blocks everywhere and the release of resources is done *explicitly*.
In C++, the mindset is different. As far as I have managed to learn,
there are two grand rules to pay attention to:
- Use exceptions for run time conditions, assert's for
logical/programmer errors.
- Use RAII (resource acquisition is initialization).
Is there any other big rule that I am missing?
As I have said earlier, one of the reasons I use C++ is when I have to
squeeze out more performance and optimizing the Python code is just
not enough. This leads me to my second question: what is the "penalty"
for using exceptions in C++? I just want to have an idea of the cost
in terms of space/time, an idea of "what to expect in general" when
using exceptions.
With my best regards,
G. Rodrigues
I've got two somewhat general questions related to exception handling
in C++. My usual programming language is the lovely and flexible
Python, but for various reasons, including the need to interface with
third-party libraries, get extra performance, etc. I have to use C++.
Now in Python, being a dynamically typed language, everything is
pushed to the run-time. Additionaly, since the language does not
guarantee deterministic destruction of objects, there are try/finally
blocks everywhere and the release of resources is done *explicitly*.
In C++, the mindset is different. As far as I have managed to learn,
there are two grand rules to pay attention to:
- Use exceptions for run time conditions, assert's for
logical/programmer errors.
- Use RAII (resource acquisition is initialization).
Is there any other big rule that I am missing?
As I have said earlier, one of the reasons I use C++ is when I have to
squeeze out more performance and optimizing the Python code is just
not enough. This leads me to my second question: what is the "penalty"
for using exceptions in C++? I just want to have an idea of the cost
in terms of space/time, an idea of "what to expect in general" when
using exceptions.
With my best regards,
G. Rodrigues