Brian Roundhill wrote:
I am having a devil of a time catching Crypto++ exceptions.
I added a wrapper file and compiled the library in Microsoft Visual
Studio. The wrapper file is C function headers to encrypt and decrypt
because one of our products is in C. Everything works fine until
something goes wrong.
Code of the problem area, with two of the catch's I've tried:
std::string szRSA; // This has the RSA private key.
try
{
pbyDecryptedData = RSADecryptString(&szRSA, (char*)byEncryptedData);
}
catch ( CryptoPP::Exception excp)
{
// Handle error
}
catch (...)
{
// Handle error
}
When we have an invalid RSA key, a BERDecodeErr exception is thrown, as
expected. In debug, this is causing a Microsoft C++ Exception, but is
then caught and handled. In release, I get 'Runtime Error!' and
'abnormal program termination'. I cannot get the catch to catch. I've
also tried std::exception.
I'm sure it's something simple and easy that I'm missing, but could
someone please point it out to me? Many thanks in advance.
I have some code that looks like this:
try
{
// If there isn't a class that has to be destroyed, VC++ 6.0
// improperly optmizes the exception frame away. This means we
// don't catch anything.
// To force the compiler to behave correctly, we instantiate
// a class that has a destructor here.
struct Junk { ~Junk() { } } junk;
::FormatMessage(...);
}
catch(...)
{
// do some stuff...
}
As the comment says, I believe this to be a bug in the VC++ 6.0.
try putting struct Junk { ~Junk() { } } junk; inside your
try block and see what happens.
Thanks,
Joseph