473,387 Members | 3,781 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,387 software developers and data experts.

Shouldn't throw built-in exceptions?

The FAQ at
http://www.parashift.com/c++-faq-lit....html#faq-17.6 says that
you shouldn't throw built-in exceptions.

I'm not sure why I shouldn't throw something like std::domain_error
though -- if it does all that I want it to do.

Joe
Apr 10 '06 #1
4 4851
Joe Van Dyk wrote:
The FAQ at
http://www.parashift.com/c++-faq-lit....html#faq-17.6 says
that you shouldn't throw built-in exceptions.
The FAQ says nothing of the kind. Read it again. It recommends against
throwing built-in _types_ (like 'int' or 'char*'), not standard exceptions.
I'm not sure why I shouldn't throw something like std::domain_error
though -- if it does all that I want it to do.


By all means, throw it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 10 '06 #2
Joe Van Dyk <jo********@boeing.com> wrote:
The FAQ at
http://www.parashift.com/c++-faq-lit....html#faq-17.6 says
that you shouldn't throw built-in exceptions.

I'm not sure why I shouldn't throw something like std::domain_error
though -- if it does all that I want it to do.


It did not say 'do not throw built-in exceptions' but 'do not throw
built-ins'. A built-in [type] is an 'int' or a 'char*'. At least how I
understood this. I do not see anything wrong with throwing an
std::runtime_exception, if it suits your needs

hth
--
jb

(reply address in rot13, unscramble first)
Apr 10 '06 #3
Jakob Bieling <ar****************@rot13.com> wrote:
understood this. I do not see anything wrong with throwing an
std::runtime_exception, if it suits your needs


Err, std::runtime_error ;-)
--
jb

(reply address in rot13, unscramble first)
Apr 10 '06 #4
Victor Bazarov wrote:
Joe Van Dyk wrote:
The FAQ at
http://www.parashift.com/c++-faq-lit....html#faq-17.6 says
that you shouldn't throw built-in exceptions.

The FAQ says nothing of the kind. Read it again. It recommends against
throwing built-in _types_ (like 'int' or 'char*'), not standard exceptions.

I'm not sure why I shouldn't throw something like std::domain_error
though -- if it does all that I want it to do.

By all means, throw it.

V

Ah, ok. They gave an example of throwing an exception object that
inherits from a standard exception, so I thought that's what the FAQ was
saying.

Thanks!
Joe
Apr 10 '06 #5

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

Similar topics

8
by: Christian Schuhegger | last post by:
hi, we are working on a c++ project which has a lot of thow list specifications which in the end causes a lot of problems. now i would like to remove them from the project. because the project...
2
by: Cheng Mo | last post by:
Below code cannot be compiled. try { throw std::string; } catch(...) { } While below is correct.
6
by: Atlas | last post by:
It's said I can't throw an ostream object, so maybe I can overload "throw" for my basic_ostream derived class?
0
by: Cheryl | last post by:
If I throw ex it does not give me enought informtion, if I throw strmessage would this actually throw the message that I've created plus the ex.message string? try { /// do something }...
3
by: Nenad Dobrilovic | last post by:
Hi, I have function which is throwning exception, like this: public class LoggedException : Exception { public void Throw() { throw this; } }
1
by: Jim Heavey | last post by:
Hello, I was setting the primary key on a table which was a collection of 3 columns. I mispelled the name of the second column when I built the array of collumns when I created the array of...
13
by: Jacek Dziedzic | last post by:
Hi! <OT, background> I am in a situation where I use two compilers from different vendors to compile my program. It seems that recently, due to a misconfiguration, library conflict or my...
7
by: > Adrian | last post by:
If I code as follows try { \\ do something } catch (.....Exception) { throw; }
6
by: Fir5tSight | last post by:
Hi, What does "throw" do? I understand that it throws an error when certain exceptional situation happens. My guess is that this *ignores* the error and *continues* so that it prevents the...
28
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
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 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.