Velocity Reviews

Velocity Reviews (
-   C++ (
-   -   Re: segmentation fault exception handling (

Ivan Vecerina 06-29-2003 10:56 PM

Re: segmentation fault exception handling
"Vasileios Zografos" <> wrote in message
> Hi, I have the following piece of code which sometimes throws a
> segmentation fault, because this.x, this.y, this.z might be unallocated
> (and it is not possible to initialize them). Its more of a geometric
> problem than programming fault.

Seg-faults during access to data members usually indicates that
the whole object itself has not been allocated adequately.

Does the 'this' pointer happen to be NULL when the segfault occurs?
Maybe what you want to do is a check such as:
if( this==0 ) .... // handle error condition...

It works in practice on some platforms, but is a bad idea in
any case, as this formally leads to undefined behavior.

As others mentioned, it *is* a programming fault to call
an object that hasn't been allocated and constructed.
The design of your code needs to be changed to avoid
such situations.

Feel free to provide more details if you want further guidance.

Ivan Vecerina, Dr. med. <>
Soft Dev Manger, XiTact <>
Brainbench MVP for C++ <>

All times are GMT. The time now is 11:02 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.