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 
       Reply  16 Jul 2026, Yiwen Yang, Info, c++ exceptions, follow up 
          Reply  16 Jul 2026, Yiwen Yang, Info, c++ exceptions, follow up main.cpp
             Reply  20 Jul 2026, Konstantin Olchanski, Info, c++ exceptions, follow up 
Message ID: 3253     Entry time: 20 Jul 2026     In reply to: 3248
Author: Konstantin Olchanski 
Topic: Info 
Subject: c++ exceptions, follow up 
> Looks like the code formatting got messed up by the elog... here it is in the attachment instead.

unfortunately, your code does nothing because you do not call "i2c_set_bit(10, 1);".

if you add it in the destructor:

~i2c_temp_bit() {
std::cout << "Bit " << bit << " set to " << oldval << "\n";
i2c_set_bit(10, 0);
}

you will burn the kitchen down if "std::cout" and "<<" throw an exception (as we know they do). (I 
always use printf(), instead of c++ exceptions, it can throw the SIGPIPE signal, so main() must 
always have signal(SIGPIPE, SIG_IGN);).

also if usleep() throws an exception, the water does not get boiled to 100 degC, important for food 
safety.

also there is a logic error, if you are at a high enough elevation (Mount Everest), water starts 
boiling well below 100 degC, so the loop never ends, probably until all water is gone and the empty 
kettle is heated to 100 degC, at this point, both kettle and heater are probably damaged. the 
infinite loop should have some kind of safety limit.

K.O.
ELOG V3.1.6-083448f7