EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: asynMotorController exception safety
From: Till Straumann <[email protected]>
To: EPICS Techtalk <[email protected]>, Mark Rivers <[email protected]>
Date: Tue, 13 Sep 2011 11:39:48 -0500
I wrote a driver class derived from asynMotorController
(which BTW was easy, thanks for the great package).

I would like the driver to be robust in case e.g., of the
absence of e.g., hardware or a serial communication channel.

Hence, my class does something like:

class MyDrv : public asynMotorController {
public:
    MyDrv() : asynMotorController(<parameters go here>)
    {
        status = detect_hardware(<parameters>);
        if ( status ) {
            throw MyException("HW detection failed\n");
        }
    }
};


In my main application I create a driver object


try {
   new MyDrv();
} catch (MyException &e) {
   printf("Unable to create driver: %s\n", e.what());
}

However, if hardware detection fails and the exception
is thrown and subsequently caught then the IOC application
will eventually (later) segfault in asynPortDriver::callbackTask()
(when trying to lock the mutex). It seems that the work
of the superclass constructor(s) (asynMotorController/asynPortDriver/...) is
not properly undone.

No segfault happens if I comment the entire try block
(including the 'new' statement), i.e., if I create no
driver at all (but still load the .db file etc.).

How am I supposed to handle failure in the constructor?

Thanks
-- Till

Replies:
RE: asynMotorController exception safety Mark Rivers

Navigate by Date:
Prev: RE: Radhard potentiometers? Eduardo Molina
Next: RE: asynMotorController exception safety Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: CA Repeater Problem with new installation of EPICS Mark Rivers
Next: RE: asynMotorController exception safety Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·