473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
Jun 28 '08 #1
2 3535
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
Jun 28 '08 #2
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
Jun 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newsgroup - Ann | last post by:
The fstream is supposed to be a replacement of the stdio.h and the exception is supposed to be a replacement of the return error code. So how do I replace my old codes of the style: if (output =...
1
by: Antti Granqvist | last post by:
Hello! I have following object relations: Competition 1--* Category 1--* Course 1 | | * Course
6
by: Jason K | last post by:
Let me preface this by saying this obviously isn't a C++ *language* issue per se; rather probably an issue relating to quality of implementation, unless I'm just misusing iostream... I wrote a...
3
by: Steven T. Hatton | last post by:
Does anyone have an opinion as to which of the std::exception derivatives is most suited from deriving file I/O exceptions from? I know I can use just about anything for an exception, but I really...
2
by: vikas | last post by:
hi, I want to generate random numbers in c++ (using vc++ 6.0) on hit of enter. I am using _kbhit(), but don't know how to reset it, so that I can use it again, can anybody help me with this. code...
2
by: ma740988 | last post by:
The hierachy for standard exception lists: bad_alloc, bad_cast, bad_typeid, logic_error, ios_base::failure, runtime_error and bad_exception runtime_error and logic_error has subsets. The...
7
by: DaVinci | last post by:
//error happen even when there existe a a.txt file #include<fstream> #include <string> #include <iostream> using std::string; using std::fstream; int main() { string s = "a.txt"; fstream...
1
by: s_amrollahi | last post by:
Dear All Hello I am Saeed Amrollahi. I encountered a very strange bug in my program. The problem is: the program reads a formatted text file of trade summary in Tehran Stock Exchange...
1
by: usenet | last post by:
I wrote some sample code (see below) for nested exception throwing i.e. my catch blocks are throwing exceptions of their own (for simplicity I used standard exceptions). I am getting some...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.