Update COMException to contain HRESULT and introduce COMInvokeException#903
Merged
matthiasblaesing merged 4 commits intojava-native-access:masterfrom Jan 13, 2018
Merged
Conversation
6731831 to
c8bd8d8
Compare
dblock
reviewed
Jan 7, 2018
| if (e.getExcepInfo() != null) { | ||
| System.out.println("bstrSource: " + e.getExcepInfo().bstrSource); | ||
| System.out.println("bstrDescription: " + e.getExcepInfo().bstrDescription); | ||
| if (e instanceof COMInvokeException) { |
Member
There was a problem hiding this comment.
This should just be a dedicated catch of COMInvokeException and there should be a catch for COMException after it that just gets ignored.
dblock
reviewed
Jan 7, 2018
|
|
||
| public void setuArgErr(int uArgErr) { | ||
| this.uArgErr = uArgErr; | ||
| public boolean matchesHresult(int errorToCheck) { |
Member
There was a problem hiding this comment.
This seems to imply that the argument is the Hresult. Should be matches or matchesErrorCode.
6a9e016 to
12ea4f5
Compare
Member
Author
|
@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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please see the details of the commits.