Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 153787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:51:47+00:00 2026-05-11T09:51:47+00:00

I stumbled upon this piece of code which seems totaly broken to me, but

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:51:47+00:00Added an answer on May 11, 2026 at 9:51 am

    If you have:

    MyObject *o = NULL;  o->func(); 

    What happens next depends on whether func is virtual. If it is, then it will crash, because it needs an object to get the vtable from. But if it’s not virtual the call proceeds with the this pointer set to NULL.

    I believe the standard says this is ‘undefined behaviour’, so anything could happen, but typical compilers just generate the code to not check whether the pointer is NULL. Some well known libraries rely on the behaviour I described: MFC has a function called something like SafeGetHandle that can be called on a null pointer, and returns NULL in that case.

    You might want to write a reusable helper function:

    void CheckNotNull(void *p) {     if (p == NULL)         throw NullPointerException(); } 

    You can then use that at the start of a function to check all its arguments, including this:

    CheckNotNull(this); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer for adjusting OC4J configuration to support Arabic do the following:… May 11, 2026 at 3:40 pm
  • added an answer Try a later build. There have been significant bug fixes… May 11, 2026 at 3:40 pm
  • added an answer CookieOfFortune has the right idea, but unfortunately the code itself… May 11, 2026 at 3:40 pm

Related Questions

Are there any ways providing an alternate GIF/PNG image, in case the user has
Hey, I stumbled upon this site looking for solutions for event overlaps in mySQL
css: .lnk { font-size:0.9em; color:#0000CC; font-family:Courier New; } How do I get the equivalent
Has anyone been able to succesfully use the IE CSS hack #IEroot? I stumbled

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.