How to catch error: The instruction at '' referenced memory at ''. The memory could n
Hi all,
I am experiencing this error: The instruction at '' referenced memory at ''. The memory could not be read. What I want to do is possibly Catch that error and execute a Go To Statement so that it will skip that part of the code altogether.
I do not know what parameter to put in the catch(<?>) block. Can anyone help me with this? Is it also possible if I want the code part where I want to GoTo is located in a different class/file?
Some additional information: This error occurs when I try to read an XML node attribute but is not present. Here is the part of the code where I think it causes this error.
_bstr_t tempb = attribute.c_str();
//Process varSource first to determine if to use WMI or TSVar
BSTR bstrAtt = tempb.copy();
pNodeMap->getNamedItem(bstrAtt,&pAtt);
pAtt->get_nodeValue(&varAtt);
Re: How to catch error: The instruction at '' referenced memory at ''. The memory cou
Originally Posted by LeanA
Hi all,
I am experiencing this error: The instruction at '' referenced memory at ''. The memory could not be read. What I want to do is possibly Catch that error and execute a Go To Statement so that it will skip that part of the code altogether.
What does your documentation say if that XML node attribute doesn't exist?
I'm sure it has to say something, as no programmer can guarantee that every single XML call will be successful.
Re: How to catch error: The instruction at '' referenced memory at ''. The memory cou
Hi Skizmo,
Oh I see, thank you. By any chance, do you know how I can check if a VARIANT has no value? I mean if it was initialized like this but did not assign any value.
VARIANT varAtt;
I am using this code now:
VARIANT varAtt;
IXMLDOMNode* pAtt = NULL;
_bstr_t tempb = attribute.c_str();
//Process varSource first to determine if to use WMI or TSVar
BSTR bstrAtt = tempb.copy();
if (pNodeMap != NULL)
{
pNodeMap->getNamedItem(bstrAtt,&pAtt);
if (pAtt != NULL)
{
pAtt->get_nodeValue(&varAtt);
SAFE_RELEASE(pAtt);
}
}
return varAtt;
So I can avoid getting an attribute if it does not exist. I want to check now if the returned VARIANT has been assigned to or not.
Re: How to catch error: The instruction at '' referenced memory at ''. The memory cou
Originally Posted by LeanA
@Paul McKenzie: If there is an error (missing attribute), the whole XML node should be skipped and process the next node.
That is what you want to do. That is not really what I was asking you.
I asked you "what does the documentation say if that node doesn't exist". Is a return code sent back to you that the function failed? Is an exception thrown that on failure?
If you expect a function to return an error code or throw an exception, you should read the documentation of that function you're calling to see what the possible return values or exceptions thrown are. You didn't do that initially, which is why I asked you to look at the documentation and see what is returned on failure.
Bookmarks