exception handling (std::ios_base::failure)

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

    exception handling (std::ios_base::failure)

    hello group,

    are there differences (run-time, ...) between the following two versions?

    ....
    catch (std::ios_base: :failure exception)
    ....

    ....
    catch (const std::ios_base:: failure& exception) // attend reference
    ....

    if not, what version do you prefer? thanks a lot!

    cheers, chris
  • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

    #2
    Re: exception handling (std::ios_base: :failure)

    On 2008-06-28 09:56, Chris Forone wrote:
    hello group,
    >
    are there differences (run-time, ...) between the following two versions?
    >
    ...
    catch (std::ios_base: :failure exception)
    ...
    >
    ...
    catch (const std::ios_base:: failure& exception) // attend reference
    ...
    Yes, the first version must create a copy of the failure object while
    the second version uses the same object that was thrown. In some cases
    this will not matter, but in others it will. If you do not know the
    difference between passing by reference and passing by value you should
    read up on it.
    if not, what version do you prefer? thanks a lot!
    The second version is the preferred one.

    --
    Erik Wikström

    Comment

    • Chris Forone

      #3
      Re: exception handling (std::ios_base: :failure)

      Erik Wikström schrieb:
      On 2008-06-28 09:56, Chris Forone wrote:
      >hello group,
      >>
      >are there differences (run-time, ...) between the following two versions?
      >>
      >...
      >catch (std::ios_base: :failure exception)
      >...
      >>
      >...
      >catch (const std::ios_base:: failure& exception) // attend reference
      >...
      >
      Yes, the first version must create a copy of the failure object while
      the second version uses the same object that was thrown. In some cases
      this will not matter, but in others it will. If you do not know the
      difference between passing by reference and passing by value you should
      read up on it.
      >
      >if not, what version do you prefer? thanks a lot!
      >
      The second version is the preferred one.
      >
      thanks! cheers, chris

      Comment

      Working...