Connecting Tech Pros Worldwide Forums | Help | Site Map

Exception information in catch(...) statement

Bernie
Guest
 
Posts: n/a
#1: Sep 1 '08
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



blargg
Guest
 
Posts: n/a
#2: Sep 1 '08

re: Exception information in catch(...) statement


In article <48bc0e12$1_3@news.bluewin.ch>, "Bernie"
<indico(at)gmx-topmail.dewrote:
Quote:
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.
Boris
Guest
 
Posts: n/a
#3: Sep 1 '08

re: Exception information in catch(...) statement


On Mon, 01 Sep 2008 17:45:18 +0200, Bernie <indico <"gmx-topmail.de>">
wrote:
Quote:
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
Salt_Peter
Guest
 
Posts: n/a
#4: Sep 2 '08

re: Exception information in catch(...) statement


On Sep 1, 11:45 am, "Bernie" <indico(at)gmx-topmail.dewrote:
Quote:
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
*/
Closed Thread