473,394 Members | 1,806 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,394 software developers and data experts.

What to derive a file I/O exception from?

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 believe it's best to derive
from std::exception, or from its derivatives.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 26 '05 #1
3 2252
* Steven T. Hatton:
Does anyone have an opinion as to which of the std::exception derivatives is
most suited from deriving file I/O exceptions from?


std::runtime_error

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 26 '05 #2
Alf P. Steinbach wrote:
* Steven T. Hatton:
Does anyone have an opinion as to which of the std::exception derivatives
is most suited from deriving file I/O exceptions from?


std::runtime_error


'std::ios_base::failure' could also be a reasonable candidate. This
class does, however, not derive from 'std::runtime_error' but only
from 'std::exception'.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Jul 26 '05 #3
On Tue, 26 Jul 2005 11:57:14 +0200, Dietmar Kuehl
<di***********@yahoo.com> wrote:
* Steven T. Hatton:
Does anyone have an opinion as to which of the std::exception derivatives
is most suited from deriving file I/O exceptions from?

'std::ios_base::failure' could also be a reasonable candidate.


I disagree. Presently, class failure is thrown by the library to
indicate some combination of state bits have been set. Code that
catches exceptions of this type will be expecting the exception to
indicate this condition, and almost certainly will be broken by this
change.

Furthermore, there is no particularly compelling reason to derive from
this class, as its common meaning is not applicable to a general I/O
error, and thus deriving from this class adds no additional meaning
over simply deriving from std::exception.

The general guideline is to use one of the specific <stdexcept>
exceptions if they fit, otherwise use std::runtime_error for runtime
exceptional conditions (non-bugs), and std::logic_error for bug
conditions.

Arguably, for the latter class of "logic errors," it is better to
simply use assert() or similar, instead of (or in addition to,
depending) throwing an exception.
Aaron W. LaFramboise

Jul 27 '05 #4

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

Similar topics

12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
3
by: codymanix | last post by:
I have a class and some of its operations are not valid under certains cercumstances. what if the user clicks on the button which lauches this operation? Should I use InvaldoperationException or...
24
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no...
9
by: Steven Blair | last post by:
Hi, I need to catch exceotions on File.Delete() After checking the help, I have noticed that thgere are serevral Exceptions that can be thrown. My question is, should I catch all thes...
7
by: Julia | last post by:
Hi I have a system which composed from 2 different components 1.MailSender 2.MailReciever the Name of my system is JuliaSystem
24
by: ypjofficial | last post by:
Hello all, I have written a class with many private data members.and i am putting it in a separate dll file. Now when i link that file while writing my main program module,natuarally i have to...
16
by: SLIMSHIM | last post by:
Hi, I"m new to c# and .net. I wrote a small program to add rows to an access table. the program goes thru the motions but the data never gets there. here is my code. I am intentionaly not using...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
3
by: vainstah | last post by:
Hello Guys and Galls, To start off, I have reached the solution I was looking for, but I would like comments and feedback on the solution I have reached and tips/tricks on making it more elegant....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.