Hi, I've read in documentation to different libraries that their
exception classes aren't subclasses from std::exception, and a separate
catch statement is required for their exceptions. Always, I don't
understand why they do so and want to fix this feature (most of the
time, I go to edit source), even in their docs they write like this:
try {
// Close the database
db.close(0);
// DbException is not subclassed from std::exception, so
// need to catch both of these.
} catch(DbException &e) {
// Error handling code goes here
} catch(std::exception &e) {
// Error handling code goes here
}
and it's obvious that even their comment is repeated. Well, if their
DbException was derived from std::exception but provided extra
functionality we still can use it, and at the same time it's possible
to catch(const std::exception&) to, at least, get some desription of
error
(this piece of code comes from db4 c++ docs)
so, why is that so common that libs provide their hierarchy of
exception classes similar to std::sceptions ??
thanks 3 2302
__PPS__ wrote: Hi, I've read in documentation to different libraries that their exception classes aren't subclasses from std::exception, and a separate catch statement is required for their exceptions. Always, I don't understand why they do so
Ask them.
and want to fix this feature (most of the time, I go to edit source), even in their docs they write like this: try { // Close the database db.close(0); // DbException is not subclassed from std::exception, so // need to catch both of these. } catch(DbException &e) { // Error handling code goes here } catch(std::exception &e) { // Error handling code goes here }
and it's obvious that even their comment is repeated.
That's an example of bad comment use.
Well, if their DbException was derived from std::exception but provided extra functionality we still can use it, and at the same time it's possible to catch(const std::exception&) to, at least, get some desription of error
(this piece of code comes from db4 c++ docs)
so, why is that so common that libs provide their hierarchy of exception classes similar to std::sceptions ??
Well, some people like to derive from std::exception, some don't. Those
who do usually say something like "you can catch any exception using
std::exception only" and those who don't usually say "my exceptions
aren't standard so they shouldn't be derived from std::exception".
It's a matter of taste.
Jonathan
On 8 Nov 2005 23:42:08 -0800, "__PPS__" <i-*********@yandex.ru> wrote: Hi, I've read in documentation to different libraries that their exception classes aren't subclasses from std::exception, and a separate catch statement is required for their exceptions. Always, I don't understand why they do so and want to fix this feature (most of the time, I go to edit source), even in their docs they write like this: try { // Close the database db.close(0); // DbException is not subclassed from std::exception, so // need to catch both of these. } catch(DbException &e) { // Error handling code goes here } catch(std::exception &e) { // Error handling code goes here }
and it's obvious that even their comment is repeated. Well, if their DbException was derived from std::exception but provided extra functionality we still can use it, and at the same time it's possible to catch(const std::exception&) to, at least, get some desription of error
(this piece of code comes from db4 c++ docs)
so, why is that so common that libs provide their hierarchy of exception classes similar to std::sceptions ?? thanks
The message function, std::exception::what(), always returns a const
char *, so if you want to use Unicode text, it means jumping through
hoops to internationalize the error message (although it *is* possible
to use std::string and const char * when UTF-8 is the chosen encoding
type).
Otherwise, it's possible that some libraries have wrapper classes
around database exceptions, OS exceptions, etc. which might not always
play well with other exception types.
--
Bob Hairgrove No**********@Home.com
* __PPS__: so, why is that so common that libs provide their hierarchy of exception classes similar to std::sceptions ??
I don't know that it's common, but where it's done it's usually obvious
that it's due to incompetence.
Some times, however, an exception that _isn't_ caught by
catch(std::exception const&) is needed, one that will propagate all the
way up through many layers of exception-catching software.
Unicode really isn't an issue, both because Unicode can be represented
as UTF-8, because exceptions should not carry user interface messages,
and because it's trivial to add a direct Unicode representation where
needed.
--
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Noah Roberts |
last post by:
I am having some problems with deriving the std::exception class. My
compiler (g++-2.95) works with it just fine, but it does in a lot of
broken cases. I have a user/developer that can't compile...
|
by: Boogie El Aceitoso |
last post by:
Hi,
I have an exception class for winapi errors (returns a formated error mesage,
usign ::GetLastError() et al, with what()).
It looks like this:
class WinapiException : public...
|
by: Pierre Rouleau |
last post by:
The std::exception class defined in the Standard C++ <exception> header
specifies that the constructors could throw any exception becuase they
do not have a throw() specification.
Why is that? ...
|
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...
|
by: Divick |
last post by:
Hi all,
I want to subclass std::exception so as to designate the type
of error that I want to throw, out of my classes, and for that I need
to store the messages inside the exception classes. I...
| |
by: Darko Miletic |
last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided
to link with multithreaded static library (/MT or /MTd option). In debug
everything works fine but in release I get this:
...
|
by: Miles |
last post by:
Hello all,
When I subclass std::exception and throw an instance of the subclass,
when I call the what() method of the caught exception, it does not
call the overridden method. I'm under the...
|
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....
|
by: dinopc |
last post by:
Hello, i am italian, I apologize for my English.
I would like to extend the class std::exception:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |