Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why does it not have a try for this throw?

37 views
Skip to first unread message

fl

unread,
Jun 15, 2015, 10:04:24 PM6/15/15
to
Hi,

I am new to throw, and C++. When I see the following snippet, I go to learn
throw. On the throw topic, it also gives try and catch. The following
snippet does not looks like written by a beginner. Could you explain it to
me on this throw usage?



Thanks,






.......................
class Number
{
friend class RealNumber;
friend class Complex;
public:
Number ();
Number & operator = (const Number &n);
Number (const Number &n);
virtual ~Number();
virtual Number operator + (Number const &n) const;
void swap (Number &n) throw ();

static Number makeReal (double r);
static Number makeComplex (double rpart, double ipart);
protected:
Number (BaseConstructor);

private:
void redefine (Number *n);
virtual Number complexAdd (Number const &n) const;
virtual Number realAdd (Number const &n) const;

Number *rep;
short referenceCount;
};

Melzzzzz

unread,
Jun 15, 2015, 11:11:58 PM6/15/15
to
On Mon, 15 Jun 2015 19:04:08 -0700 (PDT)
fl <rxj...@gmail.com> wrote:

> Hi,
>
> I am new to throw, and C++. When I see the following snippet, I go to
> learn throw. On the throw topic, it also gives try and catch. The
> following snippet does not looks like written by a beginner. Could
> you explain it to me on this throw usage?

That means empty exception specification. If function throws terminate
will be called, if not unexpected_handler installed.

Richard

unread,
Jun 16, 2015, 10:25:29 AM6/16/15
to
[Please do not mail me a copy of your followup]

fl <rxj...@gmail.com> spake the secret code
<9d409917-64a3-480c...@googlegroups.com> thusly:

> Could you explain it to me on this throw usage?

Seriously, what book are you guys getting all this really confusing
code from?

> void swap (Number &n) throw ();

This is an exception specification, which you can read about here:
<http://en.cppreference.com/w/cpp/language/except_spec>

This is deprecated since C++11 -- in other words for almost 5 years,
it has been recommended that you NOT USE THIS.

Why is this the recommendation? Because exception specifiers are an
idea borrowed from Java and they ended up causing more problems in C++
than they solved because C++ is not Java ;-).[*]

The intention with the 'throw()' exception specification is to say that
this function does not throw. This is the one useful thing that
exception specifications gave C++ and the reason why C++11 introduced
the noexcept keyword, which should be used instead:
<http://en.cppreference.com/w/cpp/language/noexcept_spec>

[*] This is my opinion. But seriously, this is usenet; do I really have
to qualify anything in my posts as my opinion? Whose opinion would be
if it wasn't mine?
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
0 new messages