Re: C++ standard library and exceptions

Discussion in 'C Programming' started by André Gillibert, Dec 12, 2011.

  1. "io_x" <> wrote:
    > +comp.lang.c
    > "ittium" <> ha scritto nel messaggio
    > news:...
    > > On 08-12-2011 PM 06:38, Goran wrote:
    > >> On Dec 8, 12:05 pm, ittium<> wrote:
    > >>> On 12/8/2011 2:32 PM, Goran wrote:
    > >>>

    >
    > i actualy think:
    > all exceptions in C or C++ library, or whatsover library,
    > but division by 0, has to be turned off
    >
    > all beahavour of seg fault or "abort()" in C or C++ library
    > or in each library, has to be minimized to 0
    >
    > for this i say all function has to return a possible
    > error code
    > all function in C has no error code are badly thinked
    >
    > this is valid too for API library OS too
    >
    >
    >


    Followup-To: comp.lang.c++

    Do you mean that the behavior of segfault should be defined as throwing
    a standard C++ exception?

    Well-defined programs cannot have any segfault... Any program having a
    segfault is in inconsistent state. Important data may have been
    damaged, and there is no guarantee of any sort of recovery.

    For the sake of security and data integrity, a good system detecting
    such an error, should kill/abort/terminate the program immediately.

    --
    André Gillibert
    André Gillibert, Dec 12, 2011
    #1
    1. Advertising

  2. On Tue, 13 Dec 2011 09:17:45 +0100
    "io_x" <> wrote:

    > yes but it is better function return error code than seg fault the
    > program e.g


    The problem is, that a segfault may corrupt the very error detection
    logic. A segfault in a process means, that there is no way the
    execution of the program can continue without being sure, something
    will break eventually somewhere else.

    The only sane reaction to a segfault is a process' equivalent to
    biological apoptosis http://en.wikipedia.org/wiki/Apoptosis

    If you want to gracefully react to a segfault, upon program start fork
    the process and install a handler for the case if it terminates with
    segfault error condition. You could even go as far as attaching to the
    process as debugger and extract the state of the process to give some
    sensible error report.

    If you were really crazy -- and I mean in the sense of a lunatic, Joker
    like madness -- you could even try to implement a system the restores
    the process state in the last sane state recorded before commencing the
    action that ultimately led to the segfault (however it's very likely
    the process will segfault again).

    A process segfaulting always means, that there is something
    fundamentally broken in the programming itself, which cannot be fixed
    by dealing with a error condition, but only by fixing the errornous
    code itself.


    Wolfgang
    Wolfgang.Draxinger, Dec 15, 2011
    #2
    1. Advertising

  3. On Dec 15, 3:14 am, "Wolfgang.Draxinger"
    <-muenchen.de> wrote:
    > On Tue, 13 Dec 2011 09:17:45 +0100
    >
    > "io_x" <> wrote:
    > > yes but it is better function return error code than seg fault the
    > > program e.g

    >
    > The problem is, that a segfault may corrupt the very error detection
    > logic. A segfault in a process means, that there is no way the
    > execution of the program can continue without being sure, something
    > will break eventually somewhere else.
    >
    > The only sane reaction to a segfault is a process' equivalent to
    > biological apoptosishttp://en.wikipedia.org/wiki/Apoptosis
    >
    > If you want to gracefully react to a segfault, upon program start fork
    > the process and install a handler for the case if it terminates with
    > segfault error condition. You could even go as far as attaching to the
    > process as debugger and extract the state of the process to give some
    > sensible error report.
    >
    > If you were really crazy -- and I mean in the sense of a lunatic, Joker
    > like madness -- you could even try to implement a system the restores
    > the process state in the last sane state recorded before commencing the
    > action that ultimately led to the segfault (however it's very likely
    > the process will segfault again).
    >
    > A process segfaulting always means, that there is something
    > fundamentally broken in the programming itself, which cannot be fixed
    > by dealing with a error condition, but only by fixing the errornous
    > code itself.


    Again, as explained else-thread, several very popular and very
    successful programs disagree with you. Examples include Sun's/Oracle's
    JVM.
    Joshua Maurice, Dec 15, 2011
    #3
  4. André Gillibert

    hanukas Guest

    On Dec 16, 1:50 am, Joshua Maurice <> wrote:
    > On Dec 15, 3:14 am, "Wolfgang.Draxinger"
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > <-muenchen.de> wrote:
    > > On Tue, 13 Dec 2011 09:17:45 +0100

    >
    > > "io_x" <> wrote:
    > > > yes but it is better function return error code than seg fault the
    > > > program e.g

    >
    > > The problem is, that a segfault may corrupt the very error detection
    > > logic. A segfault in a process means, that there is no way the
    > > execution of the program can continue without being sure, something
    > > will break eventually somewhere else.

    >
    > > The only sane reaction to a segfault is a process' equivalent to
    > > biological apoptosishttp://en.wikipedia.org/wiki/Apoptosis

    >
    > > If you want to gracefully react to a segfault, upon program start fork
    > > the process and install a handler for the case if it terminates with
    > > segfault error condition. You could even go as far as attaching to the
    > > process as debugger and extract the state of the process to give some
    > > sensible error report.

    >
    > > If you were really crazy -- and I mean in the sense of a lunatic, Joker
    > > like madness -- you could even try to implement a system the restores
    > > the process state in the last sane state recorded before commencing the
    > > action that ultimately led to the segfault (however it's very likely
    > > the process will segfault again).

    >
    > > A process segfaulting always means, that there is something
    > > fundamentally broken in the programming itself, which cannot be fixed
    > > by dealing with a error condition, but only by fixing the errornous
    > > code itself.

    >
    > Again, as explained else-thread, several very popular and very
    > successful programs disagree with you. Examples include Sun's/Oracle's
    > JVM.


    JVM.. uh huh.. okay
    hanukas, Dec 18, 2011
    #4
  5. On Dec 18, 7:02 pm, "io_x" <> wrote:
    > "Joshua Maurice" <> ha scritto nel messaggionews:...
    > On Dec 15, 3:14 am, "Wolfgang.Draxinger"
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > <-muenchen.de> wrote:
    > > On Tue, 13 Dec 2011 09:17:45 +0100

    >
    > > "io_x" <> wrote:
    > > > yes but it is better function return error code than seg fault the
    > > > program e.g

    >
    > > The problem is, that a segfault may corrupt the very error detection
    > > logic. A segfault in a process means, that there is no way the
    > > execution of the program can continue without being sure, something
    > > will break eventually somewhere else.

    >
    > > The only sane reaction to a segfault is a process' equivalent to
    > > biological apoptosishttp://en.wikipedia.org/wiki/Apoptosis

    >
    > > If you want to gracefully react to a segfault, upon program start fork
    > > the process and install a handler for the case if it terminates with
    > > segfault error condition. You could even go as far as attaching to the
    > > process as debugger and extract the state of the process to give some
    > > sensible error report.

    >
    > > If you were really crazy -- and I mean in the sense of a lunatic, Joker
    > > like madness -- you could even try to implement a system the restores
    > > the process state in the last sane state recorded before commencing the
    > > action that ultimately led to the segfault (however it's very likely
    > > the process will segfault again).

    >
    > > A process segfaulting always means, that there is something
    > > fundamentally broken in the programming itself, which cannot be fixed
    > > by dealing with a error condition, but only by fixing the errornous
    > > code itself.

    >
    > Again, as explained else-thread, several very popular and very
    > successful programs disagree with you. Examples include Sun's/Oracle's
    > JVM.
    >
    > #if these programs do that, without to detect-correct the error in the
    > #new versions of programs
    > #they make wrong
    > #because wrong write in the memory can produce indefinite result...
    > #
    > #but i say only it is better some detection first of write in memory
    > #that can be wrong memory for the program
    > #so could be no wrong write but there is a detection of the error


    Null pointer dereferences are undefined behavior by the C++ standard.
    Linux, for example, defines the behavior.

    Your proposed solution of checking the pointer for null before
    accessing carries a cost in the "not thrown" code path - the "test if
    0 and branch" instruction(s). The solution that Sun's/Oracle's JVM
    uses, that of using segfaults, carries no overhead in the "not thrown"
    code path.
    Joshua Maurice, Dec 19, 2011
    #5
    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. Fredrik Lundh
    Replies:
    0
    Views:
    432
    Fredrik Lundh
    Feb 4, 2005
  2. Daniel Bickett
    Replies:
    0
    Views:
    380
    Daniel Bickett
    Feb 4, 2005
  3. steve.leach

    How standard is the standard library?

    steve.leach, Apr 18, 2005, in forum: Python
    Replies:
    1
    Views:
    387
    Christos TZOTZIOY Georgiou
    Apr 18, 2005
  4. funkyj
    Replies:
    5
    Views:
    1,122
    funkyj
    Jan 20, 2006
  5. ittium
    Replies:
    17
    Views:
    591
    88888 Dihedral
    Dec 19, 2011
Loading...

Share This Page