473,748 Members | 10,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Catching class exception

try
{
...
}
catch (exception e)
{
cout << e.what() << endl;
}

In the code above, e is caught by value rather than polymorphically (assume
that what was thrown is derived from exception). What does the Standard say
about whether or not the call to e.what() will do the right thing? Is it
guaranteed to work, guaranteed to not work or implementation defined?

Thanks,
Dave
Jul 23 '05
11 1787
Old Wolf wrote:
[...]
You can't solve that one by thinking, without reading the
Standard. And if he should follow your suggestion and
not bother this newsgroup with questions, perhaps we should
shut down the newsgroup entirely?

Look, the Standard is available, and we're here not to re-type or
copy/paste it into our answers. That's one. Second, I am fairly
certain that even in the absence of the Standard, the OP has some
sort of documentation describing the behaviour of the 'std::exception '
class, which undoubtedly says something about this. That's two.
Third, there is other documentation readily available on the Web,
which probably describes this just as well. If that all means we
need to shut down the newsgroup, then we need to shut it down.
*I* don't think so. But the OP's question was not about something
that cannot be figured out without the newsgroup.

And I still think that questions, answers to which can be found
elsewhere, should only be asked here after a bit of thinking. That
is what I suggested. And get off my case on this.

Now,
The question is, is that a valid implementation for std::exception?
Or course it is. The Standard says nothing about what 'what' should
return except that it's an NTBS suitable for conversion and display.
It would be easy to implement std::exception in a way that
does 'work'.


That is totally irrelevant.
Jul 23 '05 #11
> Old Wolf wrote:
[...]
You can't solve that one by thinking, without reading the
Standard. And if he should follow your suggestion and
not bother this newsgroup with questions, perhaps we should
shut down the newsgroup entirely?

Look, the Standard is available, and we're here not to re-type or
copy/paste it into our answers. That's one. Second, I am fairly
certain that even in the absence of the Standard, the OP has some
sort of documentation describing the behaviour of the

'std::exception ' class, which undoubtedly says something about this. That's two.
Third, there is other documentation readily available on the Web,
which probably describes this just as well. If that all means we
need to shut down the newsgroup, then we need to shut it down.
*I* don't think so. But the OP's question was not about something
that cannot be figured out without the newsgroup.

And I still think that questions, answers to which can be found
elsewhere, should only be asked here after a bit of thinking. That
is what I suggested. And get off my case on this.

That may all be true, but you don't have to be a jerk! The Standard
may not be understandable, or the OP may not have access to the
Standard, or any number of other reasons may exist why they're posting
the question to this newsgroup.

Now,
> The question is, is that a valid implementation for
std::exception?
Or course it is. The Standard says nothing about what 'what' should
return except that it's an NTBS suitable for conversion and display.
> It would be easy to implement std::exception in a way that
> does 'work'.


That is totally irrelevant.


I could be completely wrong, but I believe the answer the OP is looking
for is that he needs to catch by reference so that the call to what()
behaves polymorphically instead of slicing the thrown object down to
std::exception.

Jul 23 '05 #12

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

Similar topics

2
1773
by: Keith Bolton | last post by:
I am handling exceptions currently using try, except. Generally I don't handle specific exceptions and am catching all. Then if an exception occurs, I would like to capture that error string. However, in the documentation it seems like there is not a way to get the extra str data if you are handling all exceptions and not specifically. Is there? thanks -keith
8
1736
by: Adam H. Peterson | last post by:
Hello, I sometimes find myself writing code something like this: try { Derived &d=dynamic_cast<Derived&>(b); d.do_something_complicated(); // etc.... } catch (std::bad_cast) { throw Base_error("An object of incorrect type was given....");
1
1528
by: vlar | last post by:
01/30/2004 I have posted "Serious bug in ngen.exe" in this thread but so far (in .NET 1.1 SP1) this bug is not yet fixed !!! So I am repeating this post again: Ngen stops catching of derived exception in multi dll application ! I have reproduced this bug in the very simple application which consists of 2 dll and 1 exe file. Its behaviour is different depending on whether it is "ngen"-ed or not: <<<ClassLibrary1.dll>>>
2
1804
by: Adam | last post by:
If I catch an exception in a static callback method like: private static void ResponseCallback(IAsnycResult asyncResult) { try { //code...code...code } catch (WebException e) { //handle exception } }
7
2340
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block of code, when System.Exception seems to get the job done for me. My application is an ASP.Net intranet site. When I catch an exception, I log the stack trace and deal with it, normally by displaying an error
12
6112
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls out of which unmanaged exception //get thrown
7
1539
by: jm.suresh | last post by:
Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. class Test(object): def _getx(self): return self._x def _setx(self,strvalue): try: self._x = float(strvalue)
12
18327
by: Karlo Lozovina | last post by:
I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ...
3
3287
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with the correct inputs for filetype #------------------------------- def readGrid( self, coord='xyz' ): mg = ( '.FALSE.', '.TRUE.' ) form = ( 'FORMATTED', 'UNFORMATTED' )
0
8989
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
8828
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,...
0
9537
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
9367
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
9319
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
6073
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
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
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.