By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

Shouldn't throw built-in exceptions?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.