Skip to content
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

Conversation

matthiasblaesing
Copy link
Member

Please see the details of the commits.

if (e.getExcepInfo() != null) {
System.out.println("bstrSource: " + e.getExcepInfo().bstrSource);
System.out.println("bstrDescription: " + e.getExcepInfo().bstrDescription);
if (e instanceof COMInvokeException) {
Copy link
Member

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) {
Copy link
Member

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.

@matthiasblaesing matthiasblaesing force-pushed the extend_comexception branch 2 times, most recently from 6a9e016 to 12ea4f5 Compare January 8, 2018 19:00
@matthiasblaesing
Copy link
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.

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
@matthiasblaesing matthiasblaesing merged commit 1ad4606 into java-native-access:master Jan 13, 2018
@matthiasblaesing matthiasblaesing deleted the extend_comexception branch January 13, 2018 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants