Alex Rivera | Logout

if (!this) { return false; }

Asked 2009-03-19T17:59:57.597
10

I stumbled upon this piece of code which seems totaly broken to me, but it does happen that this is null. I just don't get how this can be null

it is inside a normal method call such as

myObject->func();

inside MyObject::func() we have

if (!this) { return false; }

is there any way I can have the first line to throw a NullPointerException instead of going inside the null(?) method?

Edit
Report

1 Answer

-1

this == null should only occur if you are calling a method on a deleted object, or if something is writing to memory that it should not (and overwriting the object's this pointer in particular).

You should investigate what is really wrong with your code rather than trying to work around it like this.

answered 2009-03-19T18:04:18.927

Your Answer