473,379 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 1841
In article <48**********@news.bluewin.ch>, "Bernie"
<indico(at)gmx-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)gmx-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_error...

#include <iostream>
#include <stdexcept>

class error_divzero : public std::runtime_error
{
const char* pfile;
public:
error_divzero(const char* p, const char* f)
: std::runtime_error(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::runtime_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
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,...
8
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...
4
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...
4
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...
3
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...
10
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...
5
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...
6
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.