RE: [Flightgear-devel] try ... catch ... throw (up)
> Vassilii Khachaturov wrote: > I am unsure it is OK to through a temporary object like this. > It's created on the stack right there at the same frame where it's thrown, > but IIRC, as throw unwinds the stack, it is auto-destructed. You should > be throwing an object that has lifetime encompassing the outer catch > handler. Ah! Yes, that sounds correct. I'll have to go back and change my throws. Thanks, Jon ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
Re: [Flightgear-devel] try ... catch ... throw (up)
> Here's what I'm doing: > > In the Table class: > > In FGTable constructor: > > if (operation_types.find(parent_type) == string::npos) { > internal = true; > } else { > throw(string("An internal table cannot be ...")); > } > > Now, this seems to work OK - I throw an exception if a situation > occurs that is invalid. [snip] > I'm probably missing something fundamental here. Anyone have any suggestions? > > Jon I am unsure it is OK to through a temporary object like this. It's created on the stack right there at the same frame where it's thrown, but IIRC, as throw unwinds the stack, it is auto-destructed. You should be throwing an object that has lifetime encompassing the outer catch handler. ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d
[Flightgear-devel] try ... catch ... throw (up)
I've been trying to use exception handling in a particularly appropriate place in JSBSim, but am having little success, and it's got me confused. I have a section where I am reading in some data. If it is inappropriate, I need to let the user know and exit. Here's what I'm doing: In the Table class: In FGTable constructor: if (operation_types.find(parent_type) == string::npos) { internal = true; } else { throw(string("An internal table cannot be ...")); } Now, this seems to work OK - I throw an exception if a situation occurs that is invalid. Here's where the above code is originally called from: In FGFunction constructor: try { Parameters.push_back(new FGTable(PropertyManager, element)); } catch (...) {throw;} This is supposed to pass the exception on up the chain to here the code that calls the above: In FGAerodynamics::Load(): try { variables.push_back( new FGFunction(PropertyManager, function_element) ); } catch(string msg) { return false; } Execution seems to get to the "throw" in FGFunction and dies. Execution never gets to the handler in FGAerodynamics. I get a segfault. I'm probably missing something fundamental here. Anyone have any suggestions? Jon ___ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d