Hi:
In recent pondering, I am begining suspecting the usefulness of
throw specification in the language(I know this opinion have long
existed), even for delete!. The primary reason is that
reimplementing such members or functions cannot throw any types
other than specified (what would be the justifiable reason?
Besides, stack unwinding may be initiated by NPTL implemented
cancellation with unspecified throw type and compiler may enable
arithmetic exception...
From another aspect, is there any practically useful case that
throw spc. is really better than no spc. but documented?
(except high level apps infrequently called, which may want such
runtime check)
Regards 9 2704
I am glad you found the article useful.
Thanks.
Z.
I am glad you found the article useful.
Thanks,
Z.
Zorro:
From the link you provide, http://distributed-software.bl ogspot.com/2005/07/exception-m
echanism-...
A paragraph suggesting the union of the throw specification
looked inspiring. But the "First EMC Rule. The set of
exceptions that a function could throw must be a subset of
those specified at its prototype." seemd contradictory.. .
But, sorry, I am mentally confined to the question: Is there
any practically useful case that throw spc. is really better
than no spc. but documented? wi*@seed.net.tw wrote: Hi: In recent pondering, I am begining suspecting the usefulness of throw specification in the language(I know this opinion have long existed), even for delete!. The primary reason is that reimplementing such members or functions cannot throw any types other than specified (what would be the justifiable reason? Besides, stack unwinding may be initiated by NPTL implemented cancellation with unspecified throw type and compiler may enable arithmetic exception...
From another aspect, is there any practically useful case that throw spc. is really better than no spc. but documented? (except high level apps infrequently called, which may want such runtime check)
Regards
No, it's completely useless.
As are types, const etc. Just use void* for everything.
OK, perhaps types are usefull. Hmm, and const.
Come to think of it, tightly specifying everything at compile time and getting the compiler to spot errors in the form of misuse of those specifications IS pretty useful!
Ben
--
I'm not just a number. To many, I'm known as a String...
I am too old for remembering all the articles I have read over the
years. I am sure someone will be kind enough to tell you about a few
that discuss the usefulness of the throw spec.
On the contradictory part. Basically, the compiler is responsible to
ensure that in the definition (body) of the method you do not throw an
exception that was not specified at the prototype of that function.
This is because at the point of calling this method, the compiler may
only have seen the prototype (the specification of the method).
I hope this helps. My email is "zorabi" at "zhmicro.co m". It seems that
my email is not showing well if I typed it as usual.
Thanks for reading the article.
Regards,
Z.
Ben Pope wrote: wi*@seed.net.tw wrote: Hi: In recent pondering, I am begining suspecting the usefulness of throw specification in the language(I know this opinion have long existed), even for delete!. The primary reason is that reimplementing such members or functions cannot throw any types other than specified (what would be the justifiable reason? Besides, stack unwinding may be initiated by NPTL implemented cancellation with unspecified throw type and compiler may enable arithmetic exception...
From another aspect, is there any practically useful case that throw spc. is really better than no spc. but documented? (except high level apps infrequently called, which may want such runtime check)
Regards
No, it's completely useless.
As are types, const etc. Just use void* for everything.
OK, perhaps types are usefull. Hmm, and const.
Come to think of it, tightly specifying everything at compile time and getting the compiler to spot errors in the form of misuse of those specifications IS pretty useful!
The problem is that the compiler does not detect anything. Rather, the
compiler enforces the throw-specification. As an example:
int f() throw()
{
throw std::exception( "what??");
return 0;
}
This function is perfectly legal.
/Peter Ben -- I'm not just a number. To many, I'm known as a String...
Ben Pope wrote: Come to think of it, tightly specifying everything at compile time and getting the compiler to spot errors in the form of misuse of those specifications IS pretty useful!
That's one of C++'s ideal, sometimes gone too far. But I am digging
for the useful part.
No, it's completely useless.
Great! (But much harder to prove)
I'm not just a number. To many, I'm known as a String...
I'm but a mirror, all you see is yourself. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stefan Pantos |
last post by:
Dear all,
Could someone explain to me the proper use of throw()? As it is used
for std::exception. I cannot find anything which describes how it should
be used and all the information about exceptions in c++ seem to ignore
it completly. I know that it's similar to throws in java but I have no
idea of how it should be used.
When I say throw() I mean in the way it is used here:
class exception
{
|
by: Jurko Gospodnetiæ |
last post by:
Hi all.
I was wondering. Can the standard basic_string<> c_str()
member function throw any exceptions? Is it perhaps
implementation dependent?
I tried checking the standard and as far as I can see it is
implementation dependent with no guarantees what so
ever, but I was hoping I may have missed something... :-)
|
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? Is this because there could be an exception thrown when
the code creates a std::exception? I would assume that is not the case.
However, if I want to create a new exception class, derived from
std::exception (say MyException) then how can I...
|
by: anand |
last post by:
Hi
void f();
means that any type of exception may be thrown from the function. If
you say
void f() throw();
it means that no exceptions are thrown from a function
So suppose i write a code like this
|
by: Johann Gerell |
last post by:
Hi all,
Since last summer, my group has been putting throw() into the code base
as a general guideline where applicable. I've disliked it from the
beginning, since I see it as a micro-optimization at the cost of no
stack unwinding (possible data corruption) when an exception is thrown
somewhere anyway, despite the best beliefs of the programmer adding the
throw().
Now I've determined to take up the discussion for real to get rid of
| |
by: Phlip |
last post by:
C++ers:
I have this friend who thinks C++ cannot throw from a destructor.
I think throwing from a destructor is bad Karma, and should be designed
around, but that C++ cannot strictly prevent the actual event.
(One compiler-oriented reason is a compiler might not be able to detect
that the call-tree from a destructor leads to a throw.)
|
by: Ralph Moritz |
last post by:
Hi,
I've written a class called ConfigParser, which can be used to parse
config files. (Surprise!) I have overloaded the shift operators to
mimic the std iostreams. My question is, should overloaded operators
throw or not? Both are non-member friends of ConfigParser.
Cheers,
Ralph
|
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
|
by: jason.cipriani |
last post by:
Consider this program, which defines a template class who's template
parameter is the type of an exception that can be thrown by members of
the class:
=== BEGIN EXAMPLE ===
#include <iostream>
#include <string>
using namespace std;
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |