Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  16 Jul 2026, Konstantin Olchanski, Info, c++ exceptions, follow up 
    Reply  16 Jul 2026, Konstantin Olchanski, Info, c++ exceptions, follow up 
Message ID: 3246     Entry time: 16 Jul 2026     In reply to: 3245
Author: Konstantin Olchanski 
Topic: Info 
Subject: c++ exceptions, follow up 
> 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.
ELOG V3.1.6-083448f7