Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: segmentation fault exception handling (http://www.velocityreviews.com/forums/t267867-re-segmentation-fault-exception-handling.html)

Ivan Vecerina 06-29-2003 10:56 PM

Re: segmentation fault exception handling
 
"Vasileios Zografos" <vzografos@bcs.org.uk> wrote in message
news:bdnakv$qbr$1@news7.svr.pol.co.uk...
> 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.

hth,
--
Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
Soft Dev Manger, XiTact <> http://www.xitact.com
Brainbench MVP for C++ <> http://www.brainbench.com




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.