Re: segmentation fault exception handling

Discussion in 'C++' started by Ivan Vecerina, Jun 29, 2003.

  1. "Vasileios Zografos" <> wrote in message
    news:bdnakv$qbr$...
    > 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
    Ivan Vecerina, Jun 29, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    17
    Views:
    849
  2. Pud
    Replies:
    0
    Views:
    562
  3. Vasileios Zografos

    Re: segmentation fault exception handling

    Vasileios Zografos, Jun 30, 2003, in forum: C++
    Replies:
    5
    Views:
    15,573
    Pete Becker
    Jul 1, 2003
  4. eric
    Replies:
    9
    Views:
    768
    red floyd
    Jun 2, 2011
  5. O01eg Oleg
    Replies:
    6
    Views:
    224
    O01eg Oleg
    Apr 24, 2010
Loading...

Share This Page