Positioning of catch(...)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Taras_96

    Positioning of catch(...)

    Hi everyone,

    I recently came across a quiz question. Does the standard say anything
    about catch(...) being the first catch statement?

    try
    {
    }
    catch(...) // <- 'hides' subsequent catching
    {
    }
    catch(A)
    {
    }
    catch(B)
    {
    }

    I've seen numerous examples where catch(...) appears first (eg:
    Bjorne), but code doesn't compile using MS C++, so does this mean that
    the standard allows it, but some compilers don't?

    Taras
  • Jeff Schwab

    #2
    Re: Positioning of catch(...)

    Pranav wrote:
    From Wheer can I get C++ standard or it is just Bjarne Strostrup CPP
    book..,

    Comment

    • Juha Nieminen

      #3
      Re: Positioning of catch(...)

      Kai-Uwe Bux wrote:
      That says that a program where catch(...) is not the last handler in a block
      is ill-formed ("shall").
      What does "ill-formed" mean in practice? Does it have something to do
      with "undefined behavior"?

      Comment

      • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

        #4
        Re: Positioning of catch(...)

        On 2008-10-13 18:36, Juha Nieminen wrote:
        Kai-Uwe Bux wrote:
        >That says that a program where catch(...) is not the last handler in a block
        >is ill-formed ("shall").
        >
        What does "ill-formed" mean in practice? Does it have something to do
        with "undefined behavior"?
        I believe that ill-formed code is not required to compile, while
        undefined behaviour refers to the run-time behaviour (which means that
        the code did compile).

        --
        Erik Wikström

        Comment

        • James Kanze

          #5
          Re: Positioning of catch(...)

          On Oct 13, 6:39 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
          On 2008-10-13 18:36, Juha Nieminen wrote:
          Kai-Uwe Bux wrote:
          That says that a program where catch(...) is not the last
          handler in a block is ill-formed ("shall").
          What does "ill-formed" mean in practice? Does it have
          something to do with "undefined behavior"?
          I believe that ill-formed code is not required to compile,
          while undefined behaviour refers to the run-time behaviour
          (which means that the code did compile).
          Sort of. Ill-formed means that the compiler must issue a
          diagnostic. Having done so, it is free to compile the code if
          it wishes. (Good compilers generally don't.) Undefined
          behavior means just that---whatever the compiler does with the
          code is correct as far as the standard is concerned. It may
          refuse to compile it (with or without an error message); it may
          compile it do something that works; or it may compile it to do
          anything else.

          --
          James Kanze (GABI Software) email:james.kan ze@gmail.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

          Comment

          Working...