exception handling (std::ios_base::failure)

Discussion in 'C++' started by Chris Forone, Jun 28, 2008.

  1. Chris Forone

    Chris Forone Guest

    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
     
    Chris Forone, Jun 28, 2008
    #1
    1. Advertising

  2. 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
     
    Erik Wikström, Jun 28, 2008
    #2
    1. Advertising

  3. Chris Forone

    Chris Forone Guest

    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
     
    Chris Forone, Jun 29, 2008
    #3
    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. Lu
    Replies:
    0
    Views:
    465
  2. Geoffrey S. Knauth
    Replies:
    6
    Views:
    1,044
    Earl Purple
    Jan 18, 2006
  3. DaVinci
    Replies:
    3
    Views:
    434
    Jacek Dziedzic
    Apr 9, 2006
  4. DaVinci
    Replies:
    7
    Views:
    736
    Fraser Ross
    Apr 7, 2006
  5. Robin
    Replies:
    9
    Views:
    1,274
Loading...

Share This Page