473,624 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception information in catch(...) statement

Hi

is it possible to receive information like type of exception (division by
zero/null pointer/...), memory adress or source line number in a catch(...)
statement?

main()
{
try
{
// do something
} catch(...)
{
// get more information about the exception
}
}

Thanks.
Bernie
Sep 1 '08 #1
3 1855
In article <48**********@n ews.bluewin.ch> , "Bernie"
<indico(at)gm x-topmail.dewrote :
is it possible to receive information like type of exception (division by
zero/null pointer/...), memory adress or source line number in a catch(...)
statement?
[...]
The result of such conditions is undefined and the standard places no
requirements on what a compiler does. A particular compiler might support
this, but it's misguided since such conditions are conceptually at a lower
level than the exception handling mechanism; aborting the program is
usually the best response.
Sep 1 '08 #2
On Mon, 01 Sep 2008 17:45:18 +0200, Bernie <indico <"gmx-topmail.de>">
wrote:
is it possible to receive information like type of exception (division by
zero/null pointer/...), memory adress or source line number in a
catch(...)
statement?
Creating and analyzing application crash dumps might be more helpful to
fix those bugs which slipped through testing and can only be reliably
reproduced by customers. :)

Boris
Sep 1 '08 #3
On Sep 1, 11:45 am, "Bernie" <indico(at)gm x-topmail.dewrote :
Hi

is it possible to receive information like type of exception (division by
zero/null pointer/...), memory adress or source line number in a catch(...)
statement?

main()
{
try
{
// do something
} catch(...)
{
// get more information about the exception
}

}

Thanks.
Bernie
derive from std::runtime_er ror...

#include <iostream>
#include <stdexcept>

class error_divzero : public std::runtime_er ror
{
const char* pfile;
public:
error_divzero(c onst char* p, const char* f)
: std::runtime_er ror(p), pfile(f) { }
// member
const char* what() const throw()
{
return pfile;
}
};

int main()
{
try
{
int x(1);
int y(0);
y ? x/y : throw error_divzero(" divide by zero", __FILE__);
}
catch (const error_divzero& r_e )
{
std::cout << "Error: ";
std::cout << r_e.std::runtim e_error::what() << std::endl;
std::cout << r_e.what() << std::endl;
}
catch (const std::exception& r_e )
{
std::cout << "Error: ";
std::cout << r_e.what() << std::endl;
}
}

/*
Error: divide by zero
/%somepath%/test.cpp
*/
Sep 2 '08 #4

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

Similar topics

6
1491
by: C# Learner | last post by:
In the following two code blocks, DoSomethingUseful throws AnException, while neither of the other called methods throw any exceptions. Which of the code blocks is better (in terms of readability, maintainability, etc.), in your opinions? A { Start(); try {
8
1381
by: Jonah Olsson | last post by:
Hi guys, For my VB.NET application, I created an ErrorHandler class that should save all available information about the last error occurred. I use Server.GetLastError for this. The problem is that I quite often get errors that I really can't say why they happen because of the lack of information from GetLastError. This is an example: System.NullReferenceException: Object reference not set to an instance of an
4
2715
by: Grant | last post by:
I want to be able to accept a value in "goToTextBox.Text" if it is a decimal value such as 3.4. My Try statement currently catches non-numeric or blank data, which I want to retain. How can I accomplish this? T.I.A. Grant Try
4
1358
by: Steve | last post by:
Hi All In VB6 I used to catch exceptions in a goto errtrap call then resume if I could handle the problem and continue within the routine or function I am not sure how to do this in VB 2005 from within a catch statement Any ideas appreciated
3
7774
by: Koen | last post by:
Hi, I have been reading a bit basic stuff about method attributes in C#, and I wanted to build the following functionality with it: if a method has the custom attribute <LogException> the method has to be wrapped as follows: try {
10
1496
by: tony | last post by:
Hello!! As you know every user defined exception must be derived from class Exception. Now to my question if I write catch then every exception will be caught. If I instead write catch(Exception) then every exception will also be caught. These two will catch the exact same exception is this right understod?
5
1829
by: Back 9 | last post by:
I try to insert try/catch statement in every single method of my c# code to prevent the app from crashing not nicely. Do you think it is good idea? I remember that an artical says " do not overuse try/catch " but I don't remember the reason why I should overuser. I don't see the reason I should not overuse them. What's your opinion on it? Thx
6
2028
by: Fir5tSight | last post by:
Hi, What does "throw" do? I understand that it throws an error when certain exceptional situation happens. My guess is that this *ignores* the error and *continues* so that it prevents the program from crashing. I just don't know where it throws the error to? It makes sense if it outputs the error into a log file. Please let me know if my thoughts are correct.
2
2195
by: AnnetteB | last post by:
I have an action performed on the click of a button which basically opens up a text file based on the textfield input of the user. I would like to use an if statement to say if the variable already exists to give a message saying file name already used. I didn't want to use file reader as I wanted to specify the exact location of the files. I have put an if statement inside the try catch of the action performed, but it won't work?? Can...
0
8236
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
8679
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...
1
8335
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
8475
tracyyun
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...
0
7159
agi2029
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...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
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
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
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.