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
*/