473,651 Members | 3,036 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_err or
though -- if it does all that I want it to do.

Joe
Apr 10 '06 #1
4 4864
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_err or
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********@boe ing.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_err or
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_ex ception, 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_ex ception, if it suits your needs


Err, std::runtime_er ror ;-)
--
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_err or
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
1755
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 has a size of 300000+ lines of code it is not so easy to do all of that manually. therefore my question: is there a tool that you run on your sources and which just converts the throw declarations into a comment? a tool that only comments the...
2
2898
by: Cheng Mo | last post by:
Below code cannot be compiled. try { throw std::string; } catch(...) { } While below is correct.
6
2728
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
294
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 } catch(Exception ex)
3
2354
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
3298
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 collumns for the primary key. When I used the "dt.primarykey(myArrayOfKeys)" no exception was thrown, and rather then the primary key being a set of 3 columns, it was only a single column. When you make this type of mistake when setting foreign keys,...
13
2054
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 ignorance, with one of the compilers I am having trouble related to libuwind.so, which, to my knowledge, deals with the intricacies of unwinding the stack upon an exception. Executables compiled with this compiler crash with a SEGV after throw(), never...
7
1390
by: > Adrian | last post by:
If I code as follows try { \\ do something } catch (.....Exception) { throw; }
6
2029
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 program from crashing. I just don't know where it throws the error to? It makes sense if it outputs the error into a log file. Please let me know if my thoughts are correct.
28
2839
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 apply. Can somebody tell me why? Thanks, Jess
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8807
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.