473,699 Members | 2,501 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 1782
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
1770
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
1733
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
1526
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
1802
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
2337
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
6105
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
1538
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
18307
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
3283
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
9172
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
9032
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
8908
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,...
1
6532
isladogs
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...
0
5869
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
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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
3
2008
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.