-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update COMException to contain HRESULT and introduce COMInvokeException #903
Update COMException to contain HRESULT and introduce COMInvokeException #903
Conversation
6731831
to
c8bd8d8
Compare
if (e.getExcepInfo() != null) { | ||
System.out.println("bstrSource: " + e.getExcepInfo().bstrSource); | ||
System.out.println("bstrDescription: " + e.getExcepInfo().bstrDescription); | ||
if (e instanceof COMInvokeException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be a dedicated catch of COMInvokeException
and there should be a catch for COMException
after it that just gets ignored.
|
||
public void setuArgErr(int uArgErr) { | ||
this.uArgErr = uArgErr; | ||
public boolean matchesHresult(int errorToCheck) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to imply that the argument is the Hresult. Should be matches
or matchesErrorCode
.
6a9e016
to
12ea4f5
Compare
@dblock Thanks for looking into this. I adjusted the commits, for the msoffice sample I completely agree, for the "COMException#matchesErrorCode" I have no strong feelings either way. I think the javadoc was ok, but I adjusted the method name and am ok with it. |
12ea4f5
to
fb58d49
Compare
This allows filtering exception based on HRESULT value. For example GetActiveObject returns a HRESULT of 0x800401E3 (MK_E_UNAVAILABLE) if the target object is not active. For many cases this is not an error. A valid construct would be: public void getExistingDemoObjectOrCreate() { DemoObject obj; try { return factory.fetchObject(DemoObject.class); } catch (COMException ex) { if(ex.matchesHresult(WinError.MK_E_UNAVAILABLE)) { return factory.createObject(DemoObject.class); } else { throw ex; } } }
…lure Only a subset of errors contain exception data. Only calls to IDispatch#Invoke generate exception details and potentially a "fault index" for parameters. Therefore these are separated into an extended COMInvokeException. Additionally the EXCEPINFO data was not freeed, leading to memory leaks in in repeated calls. Add unittest for COMExceptions and correct Exception extraction in Factory
fb58d49
to
bf680a5
Compare
Please see the details of the commits.