注意:尝试获取非对象调试错误的属性

When the 404 page is triggered, I get a

Notice: Trying to get property of non-object

on the following lines of code when in debug mode

$custom = get_post_custom($post->ID);

and

$parent_id    = $parent_id_2  = $post->post_parent;

I know this is suppose to happen because the 404 page triggers because the are no post to show in the first place. To get rid of these notices I need to do a check first to see if there is a post to show. My problem is, exactly how do I do it. Any suggestions?

I would tend to do something like

if (isset($post)){
    //action goes here
}

so the action is only performed if post has been set.