Re: cannot catch exception
- From: "Vaclav" <no@xxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 23:18:03 +0100
I changed the code to be:
if (!pObj)
{
continue;
}
try
{
//if pObj is some garbage
//the next line will blow up
pObj->GetPosition();
}
catch(...)
{
//let us skip invalid pObj
AfxMessageBox("got exception");
continue;
}
The first test is passed because there is something in the variable (but not
a valid object).
The pObj is taken from a collection. Something like
CDrawObj* pObj = m_objects.GetNext(pos);
And I changed calling method IsValid() to method GetPosition() which returns
coordinates of the object.
The exception is still not caught.
Vaclav
"Josh McFarlane" <darsant@xxxxxxxxx> píse v diskusním príspevku
news:1133301975.992985.102180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Vaclav wrote:
>> if (!pObj->IsValid())
>> {
>> continue;
>> }
>> The problem disappears when I turn optimization off. The question is why
>> the
>> handler is not called?
>
> The compiler is looking at IsValid, seeing that it always returns true,
> and skipping the entire thing all together.
>
> Two more questions:
> Is the pointer initialized to NULL?
> If so, you can do the following to check to see if a value has been
> passed:
>
> if (pObj)
> {
> //Valid pointer
> //Do stuff
> }
> else
> {
> //Invalid pointer
> //Complain
> }
>
> If the previous answer was yes, and you still have invalid pointers,
> how is that occuring?
>
.
- Follow-Ups:
- Re: cannot catch exception
- From: Josh McFarlane
- Re: cannot catch exception
- References:
- cannot catch exception
- From: Vaclav
- Re: cannot catch exception
- From: Josh McFarlane
- Re: cannot catch exception
- From: Vaclav
- Re: cannot catch exception
- From: Josh McFarlane
- cannot catch exception
- Prev by Date: Re: cannot catch exception
- Next by Date: Re: cannot catch exception
- Previous by thread: Re: cannot catch exception
- Next by thread: Re: cannot catch exception
- Index(es):
Relevant Pages
|