I want to check in code to eliminate the use of exceptions in iPic3D.
Allowing exceptions has performance penalties. In particular, while developing an array class for iPic3D, I observed that looping through array elements took three times as long if the body of the destructor of the array class was nonempty. This performance penalty disappeared when I compiled with the -fno-exceptions flag.
I see no reason to retain exception handling in iPic3D. This is not an event-driven application. All current use of exceptions is used to generate error messages, which can be handled adequately with simple calls to eprintf(). Therefore, I am going through the code and replacing each throwing of an exception such as
eprintf("make_dataset fails for %s", tag.c_str());
Note that the eprintf() macro automatically prints file, line number, and method name, so there is no need to add any of that information to the call to eprintf().
In my initial implementation of this change I simply comment out all occurences of try and all catch blocks and all calls to throw, replacing each call to throw with a call to eprintf. I leave it for later to decide whether to completely eliminate the Exception and OutputException classes in the PSK namespace or whether for some reason to revert to supporting the possibility of exceptions via pre-processor branching directives.
I want to check in code to eliminate the use of exceptions in iPic3D.
Allowing exceptions has performance penalties. In particular, while developing an array class for iPic3D, I observed that looping through array elements took three times as long if the body of the destructor of the array class was nonempty. This performance penalty disappeared when I compiled with the
-fno-exceptions
flag.I see no reason to retain exception handling in iPic3D. This is not an event-driven application. All current use of exceptions is used to generate error messages, which can be handled adequately with simple calls to
eprintf()
. Therefore, I am going through the code and replacing each throwing of an exception such aswith printing of an error message such as
Note that the
eprintf()
macro automatically prints file, line number, and method name, so there is no need to add any of that information to the call toeprintf()
.In my initial implementation of this change I simply comment out all occurences of
try
and allcatch
blocks and all calls tothrow
, replacing each call tothrow
with a call toeprintf
. I leave it for later to decide whether to completely eliminate theException
andOutputException
classes in thePSK
namespace or whether for some reason to revert to supporting the possibility of exceptions via pre-processor branching directives.