> If you did not want to use exceptions before watching this talk, you will after!
Not me. One issue, exceptions are unpredictable, for example, does this code always print "hello, world"?
#include <stdio.h>
#include "foo.h"
int main(...)
{
foo();
printf("hello, world\n");
return 0;
}
I can wrap foo() (and each and every function call) in try/catch.
I can check if today's version of foo.h declares foo() as "nothrow" (but what if tomorrow's foo() start
throwing?)
Unpredictable code can be dangerous:
void boil_kettle()
{
i2c_set_bit(10, 1); // bit 10 is stove heater control, turn it on
foo(); // wait for kettle to start boiling
i2c_set_bit(10, 0); // turn heater off
}
If foo() starts throwing exceptions, I will likely have a fire in my kitchen!
K.O. |