Exceptions in C/C++

Discussion in 'C Programming' started by opexoc@gmail.com, Dec 7, 2007.

  1. Guest

    Hello,

    I have question concerning such code:

    __try
    {
    ...
    } __except(EXCEPTION_EXECUTE_HANDLER)
    {
    printf("Exception code: %.8x\n", GetExceptionCode());
    }


    Is C related code? Or maybe C++?

    opexoc
    , Dec 7, 2007
    #1
    1. Advertising

  2. Tor Rustad Guest

    wrote:
    > Hello,
    >
    > I have question concerning such code:
    >
    > __try
    > {
    > ...
    > } __except(EXCEPTION_EXECUTE_HANDLER)
    > {
    > printf("Exception code: %.8x\n", GetExceptionCode());
    > }
    >
    >
    > Is C related code? Or maybe C++?


    It's not ISO C, but Microsoft specific C, see their MSDN doc.

    --
    Tor < | tr i-za-h a-z>
    Tor Rustad, Dec 7, 2007
    #2
    1. Advertising

  3. Guest

    So if I want to use exceptions catching in dev-cpp in C code then what
    should I do?

    On 7 Gru, 01:58, Tor Rustad <> wrote:
    >
    > It's not ISO C, but Microsoft specific C, see their MSDN doc.
    , Dec 7, 2007
    #3
  4. jacob navia Guest

    wrote:
    > So if I want to use exceptions catching in dev-cpp in C code then what
    > should I do?
    >
    > On 7 Gru, 01:58, Tor Rustad <> wrote:
    >> It's not ISO C, but Microsoft specific C, see their MSDN doc.

    >
    >


    If you use the lcc-win compiler you can use the
    __try/__except construct.

    URL below

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Dec 7, 2007
    #4
  5. Guest

    On 7 Gru, 14:59, jacob navia <> wrote:
    > wrote:
    > > So if I want to use exceptions catching in dev-cpp in C code then what
    > > should I do?

    >
    > > On 7 Gru, 01:58, Tor Rustad <> wrote:
    > >> It's not ISO C, but Microsoft specific C, see their MSDN doc.

    >
    > If you use the lcc-win compiler you can use the
    > __try/__except construct.


    Ok but dec-cpp has any construct which is to catching exception for C
    language?
    , Dec 7, 2007
    #5
  6. Guest

    On Dec 7, 1:59 pm, jacob navia <> wrote:
    > wrote:
    > > So if I want to use exceptions catching in dev-cpp in C code then what
    > > should I do?

    >
    > > On 7 Gru, 01:58, Tor Rustad <> wrote:
    > >> It's not ISO C, but Microsoft specific C, see their MSDN doc.

    >
    > If you use the lcc-win compiler you can use the
    > __try/__except construct.
    >
    > URL below


    Rather than using extensions that tie your code to a particular
    compiler and platform, why not use the perfectly good exception-
    handling features already present in standard C, namely setjmp()/
    longjmp()?

    >
    > --
    > jacob navia
    > jacob at jacob point remcomp point fr
    > logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
    , Dec 7, 2007
    #6
  7. jacob navia Guest

    wrote:
    > On 7 Gru, 14:59, jacob navia <> wrote:
    >> wrote:
    >>> So if I want to use exceptions catching in dev-cpp in C code then what
    >>> should I do?
    >>> On 7 Gru, 01:58, Tor Rustad <> wrote:
    >>>> It's not ISO C, but Microsoft specific C, see their MSDN doc.

    >> If you use the lcc-win compiler you can use the
    >> __try/__except construct.

    >
    > Ok but dec-cpp has any construct which is to catching exception for C
    > language?
    >
    >
    >


    dev-cpp is an IDE. The compiler used is gcc in its "mingw" incarnation.
    As fas as I know there isn't anything like that in gcc.

    Therefore is not there for devcpp


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Dec 7, 2007
    #7
  8. jacob navia Guest

    wrote:
    >
    > Rather than using extensions that tie your code to a particular
    > compiler and platform, why not use the perfectly good exception-
    > handling features already present in standard C, namely setjmp()/
    > longjmp()?
    >


    because they do not do what exceptions do.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Dec 7, 2007
    #8
  9. Guest

    In article <>,
    <> wrote:

    >Rather than using extensions that tie your code to a particular
    >compiler and platform, why not use the perfectly good exception-
    >handling features already present in standard C, namely setjmp()/
    >longjmp()?


    setjmp and longjmp are not exactly "perfectly good exception-handling
    features"; setjmp is merely a restricted COME FROM, and longjmp marks
    acceptable targets for it.

    It's possible to build a perfectly good exception-handling system on
    top of setjmp/longjmp, but it does have to be built.


    dave
    , Dec 7, 2007
    #9
  10. In article <fjbo08$hso$>,
    <> wrote:

    >setjmp and longjmp are not exactly "perfectly good exception-handling
    >features"; setjmp is merely a restricted COME FROM, and longjmp marks
    >acceptable targets for it.


    The whole point of COME FROM is that the jumped-from location isn't
    marked.

    -- Richard
    --
    :wq
    Richard Tobin, Dec 7, 2007
    #10
  11. Guest


    > dev-cpp is an IDE. The compiler used is gcc in its "mingw" incarnation.
    > As fas as I know there isn't anything like that in gcc.
    >
    > Therefore is not there for devcpp


    So it is not possible to use exceptions catching in dev-cpp?

    opexoc
    , Dec 7, 2007
    #11
  12. wrote:
    >> dev-cpp is an IDE. The compiler used is gcc in its "mingw" incarnation.
    >> As fas as I know there isn't anything like that in gcc.
    >>
    >> Therefore is not there for devcpp

    >
    > So it is not possible to use exceptions catching in dev-cpp?


    Why don't you either
    a) Read the Manual; or
    b) ask in a dev-cpp newsgroup, mailing list etc etc?

    This is NOT the right place.
    --
    Mark McIntyre

    CLC FAQ <http://c-faq.com/>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
    Mark McIntyre, Dec 7, 2007
    #12
  13. jacob navia Guest

    wrote:
    >> dev-cpp is an IDE. The compiler used is gcc in its "mingw" incarnation.
    >> As fas as I know there isn't anything like that in gcc.
    >>
    >> Therefore is not there for devcpp

    >
    > So it is not possible to use exceptions catching in dev-cpp?
    >
    > opexoc
    >
    >


    I do not think so


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Dec 7, 2007
    #13
  14. CBFalconer Guest

    jacob navia wrote:
    > wrote:
    >
    >> Rather than using extensions that tie your code to a particular
    >> compiler and platform, why not use the perfectly good exception-
    >> handling features already present in standard C, namely setjmp()/
    >> longjmp()?

    >
    > because they do not do what exceptions do.


    Aha. Now you may be beginning to see why exceptions (as built into
    the language) are off-topic on c.l.c. Hint: try c.l.c++, which
    handles a language with such a feature.

    --
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>
    Try the download section.



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Dec 8, 2007
    #14
  15. Guest

    In article <fjbpa1$1mc9$>,
    Richard Tobin <> wrote:
    >In article <fjbo08$hso$>,
    > <> wrote:
    >
    >>setjmp and longjmp are not exactly "perfectly good exception-handling
    >>features"; setjmp is merely a restricted COME FROM, and longjmp marks
    >>acceptable targets for it.

    >
    >The whole point of COME FROM is that the jumped-from location isn't
    >marked.


    No, that was a side goal of the original implementation.
    The point of COME FROM is that the destination of a jump (the location
    of the COME FROM) can be changed on the fly for a particular origin
    (target of the COME FROM); setjmp/longjmp require that the source and
    destination be marked (and the longjmp needs to be wrapped in a test if
    you want it to not jump until a setjmp has asked to COME FROM it), but
    which setjmp a longjmp jumps to can be dynamically modified.


    dave
    , Dec 8, 2007
    #15
  16. <> wrote in message
    >
    >> dev-cpp is an IDE. The compiler used is gcc in its "mingw" incarnation.
    >> As fas as I know there isn't anything like that in gcc.
    >>
    >> Therefore is not there for devcpp

    >
    > So it is not possible to use exceptions catching in dev-cpp?
    >

    try ... catch ... throw is a fairly common extension that both lcc-win and
    Microsft's compiler seem to support. Opinions will differ on whether it is a
    good idea.
    One indisputable disadvantage is that you then cannot port code to any
    arbitrary C platform. Though I've got considerable experience in C on a wide
    variety of compilers and targets, I couldn't possibly list the
    characteristics of each and every one on the market.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Dec 8, 2007
    #16
  17. In article <fjcokr$sts$>,
    <> wrote:

    >>The whole point of COME FROM is that the jumped-from location isn't
    >>marked.


    >No, that was a side goal of the original implementation.
    >The point of COME FROM is that the destination of a jump (the location
    >of the COME FROM) can be changed on the fly for a particular origin
    >(target of the COME FROM); setjmp/longjmp require that the source and
    >destination be marked (and the longjmp needs to be wrapped in a test if
    >you want it to not jump until a setjmp has asked to COME FROM it), but
    >which setjmp a longjmp jumps to can be dynamically modified.


    What you are describing seems more like ASSIGNED GO TO (provided in C
    by a GNU extension). In all forms of GO TO, including longjmp(), the
    jump destination is specified at the jump source by an argument of the
    GO TO. In COME FROM, the jump source is specified at the jump
    destination by an argument of the COME FROM. With setjmp()/longjmp()
    there is no way to set the jump source at the jump destination (ie the
    setjmp()).

    Variability of one end of the jump is an orthogonal feature provided
    by ASSIGNED GO TO and ASSIGNED COME FROM. It's not the difference
    between GO TO and COME FROM.

    -- Richard

    --
    :wq
    Richard Tobin, Dec 8, 2007
    #17
  18. jacob navia Guest

    CBFalconer wrote:
    > jacob navia wrote:
    >> wrote:
    >>
    >>> Rather than using extensions that tie your code to a particular
    >>> compiler and platform, why not use the perfectly good exception-
    >>> handling features already present in standard C, namely setjmp()/
    >>> longjmp()?

    >> because they do not do what exceptions do.

    >
    > Aha. Now you may be beginning to see why exceptions (as built into
    > the language) are off-topic on c.l.c. Hint: try c.l.c++, which
    > handles a language with such a feature.
    >


    It is not off topic. It is about exceptions in C.

    Clear?

    And if you do not like a subject, just skip it.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Dec 8, 2007
    #18
  19. Flash Gordon Guest

    jacob navia wrote, On 08/12/07 12:18:
    > CBFalconer wrote:
    >> jacob navia wrote:
    >>> wrote:
    >>>
    >>>> Rather than using extensions that tie your code to a particular
    >>>> compiler and platform, why not use the perfectly good exception-
    >>>> handling features already present in standard C, namely setjmp()/
    >>>> longjmp()?
    >>> because they do not do what exceptions do.

    >>
    >> Aha. Now you may be beginning to see why exceptions (as built into
    >> the language) are off-topic on c.l.c. Hint: try c.l.c++, which
    >> handles a language with such a feature.

    >
    > It is not off topic. It is about exceptions in C.
    >
    > Clear?


    OK, the answer is easy then, there aren't any.

    The suggestion of trying C++ which *does* have exceptions was a sensible
    one. The suggestion of asking somewhere where the compiler the OP was
    interested in (which was not yours of MSVC++) was also sensible. The
    suggestion of implementing something using setjmp/longjmp was sensible
    since it allows staying with standard C (although it might not provide
    the functionality wanted by the OP). Suggesting switching to a compiler
    specific extension provided by a couple of other compilers does *not*
    answer the OPs question.

    > And if you do not like a subject, just skip it.


    If you don't like the subject of the group then just skip the group.
    --
    Flash Gordon
    Flash Gordon, Dec 8, 2007
    #19
  20. jacob navia Guest

    Flash Gordon wrote:
    > jacob navia wrote, On 08/12/07 12:18:
    >> CBFalconer wrote:
    >>> jacob navia wrote:
    >>>> wrote:
    >>>>
    >>>>> Rather than using extensions that tie your code to a particular
    >>>>> compiler and platform, why not use the perfectly good exception-
    >>>>> handling features already present in standard C, namely setjmp()/
    >>>>> longjmp()?
    >>>> because they do not do what exceptions do.
    >>>
    >>> Aha. Now you may be beginning to see why exceptions (as built into
    >>> the language) are off-topic on c.l.c. Hint: try c.l.c++, which
    >>> handles a language with such a feature.

    >>
    >> It is not off topic. It is about exceptions in C.
    >>
    >> Clear?

    >
    > OK, the answer is easy then, there aren't any.
    >
    > The suggestion of trying C++ which *does* have exceptions was a sensible
    > one. The suggestion of asking somewhere where the compiler the OP was
    > interested in (which was not yours of MSVC++) was also sensible. The
    > suggestion of implementing something using setjmp/longjmp was sensible
    > since it allows staying with standard C (although it might not provide
    > the functionality wanted by the OP). Suggesting switching to a compiler
    > specific extension provided by a couple of other compilers does *not*
    > answer the OPs question.
    >
    >> And if you do not like a subject, just skip it.

    >
    > If you don't like the subject of the group then just skip the group.


    The subject of the group is C. Nowhere in the charter was mentioned
    that it was just ISO C.

    Microsoft, lcc-win, and other compilers under windows implement
    __try/__except. And if you do not like it it is your problem, not
    mine. It is a common extension under windows.



    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Dec 8, 2007
    #20
    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. Herr Lucifer
    Replies:
    0
    Views:
    528
    Herr Lucifer
    Jun 21, 2004
  2. Ahmed Moustafa
    Replies:
    5
    Views:
    29,971
    Chris Smith
    Jul 14, 2004
  3. Paul Miller
    Replies:
    3
    Views:
    996
    Alex Martelli
    Nov 12, 2003
  4. Replies:
    3
    Views:
    584
    Sherm Pendley
    Apr 16, 2007
  5. Lie
    Replies:
    3
    Views:
    590
Loading...

Share This Page