I am trying to figure the best mechanism for setting an error flag from attach extension.
This is the recompute stack:
Code: Select all
#0 Part::AttachExtension::extensionExecute()
#1 App::DocumentObject::execute()
#2 Part::Feature::execute()
#3 App::DocumentObject::recompute()
#4 Part::Feature::recompute()
#5 App::Document::_recomputeFeature()
#6 App::Document::recompute()
I have managed to make it work like this. In #0:
Code: Select all
if(acceptableattachment) {
positionBySupport();
}
else {
throw Base::ValueError("Current support is invalid for the selected mapping mode");
}
/*} catch (Base::Exception &e) {
return new App::DocumentObjectExecReturn(e.what());*/
Note that I had to comment out the catch(Base:Exception).
Why?
I had to do that because:
1. The one ultimately controlling the setting of the flag (and that will clear it if not receiving what it expects) is: Document::_recomputeFeature(DocumentObject* Feat) #5
2. This function will reset any flag set unless: a) the return code is not DocumentObject::StdReturn or b) a Base:Exception was thrown during the execution of the Feature->recompute() #4
3. Feature->recompute() #4 will return whatever #3 returned
4. #3 will return whatever #2 returned
5. #2 will return whatever #1 returned
6. #1 always,
unconditionally returns StdReturn
7. at #0, the commented Base::Exception would catch my Base::ValueError exception that is derived from Base::Exception, thereby removing any hope of propagating the error information to #5
Now somebody took extraordinary care to catch all possible exceptions in #0 and return an "App::DocumentObjectExecReturn" which is nevertheless ignored in #1.
And that is the ultimate reason why I am writing this.
Is there any reason for this? Can I just propagate all Base::Exceptions as with the commented code?
I also can catch first a Base::ValueError to re-throw the same and avoid the catching by Base::Exception that may be needed for other exceptions, but in such a case I am not returning the "App::DocumentObjectExecReturn".
Sorry for the long post and thanks in advance.