M
Martin
Hi.
I need to identify the type of the exception in the universal handler
(catch (...)) for debugging purposes. Point is that I write a testing
console application, which must call some functions from a DLL. One of
these functions throws an exception, and since my small application
knows nothing about the exception type system of that DLL application,
the generated exception always caught in 'catch (...)'. I've made some
small investigations: it turned out (as I could understand...), that
MSVC recognizes the right handler by the name of the exception type.
E.g., I've created a DLL, exporting function 'Func', throwing an
object of type 'A':
*** DLL's implementation part ***
class A
{
public:
int m_a, m_b;
double m_c;
};
__declspec(dllexport) int Func()
{
throw A();
}
*************************************
And here's a small .exe, which will call 'Func' from DLL:
*** EXE's implementation part ***
class A
{
};
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
try
{
Func();
}
catch (const A&)
{
cerr << "Caught 'A'\n";
}
catch (...)
{
cerr << "Unknown exception...\n";
}
return 0;
}
**********************************************************
It's surprising, that the program writes out "Caught 'A'", though
conceptually the type of the thrown object is not the same... And this
makes me think, that runtime somehow knows the name of the thrown
type, and moreover, it identifies the needed handler by the NAME of
the type of exception object. So, how to obtain that name in catch
(...)?
Thanks in advance
Martin
I need to identify the type of the exception in the universal handler
(catch (...)) for debugging purposes. Point is that I write a testing
console application, which must call some functions from a DLL. One of
these functions throws an exception, and since my small application
knows nothing about the exception type system of that DLL application,
the generated exception always caught in 'catch (...)'. I've made some
small investigations: it turned out (as I could understand...), that
MSVC recognizes the right handler by the name of the exception type.
E.g., I've created a DLL, exporting function 'Func', throwing an
object of type 'A':
*** DLL's implementation part ***
class A
{
public:
int m_a, m_b;
double m_c;
};
__declspec(dllexport) int Func()
{
throw A();
}
*************************************
And here's a small .exe, which will call 'Func' from DLL:
*** EXE's implementation part ***
class A
{
};
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
try
{
Func();
}
catch (const A&)
{
cerr << "Caught 'A'\n";
}
catch (...)
{
cerr << "Unknown exception...\n";
}
return 0;
}
**********************************************************
It's surprising, that the program writes out "Caught 'A'", though
conceptually the type of the thrown object is not the same... And this
makes me think, that runtime somehow knows the name of the thrown
type, and moreover, it identifies the needed handler by the NAME of
the type of exception object. So, how to obtain that name in catch
(...)?
Thanks in advance
Martin