Hi
Here is an example of my problem. I am running thhis inside Eclispe 2.1.1 using the CPPUnit Plugin. If I comment ou the call o throwException() I get the expected CPP_FAIL. If I catch the exception it does not execute the CPP_FAIL, but uses a generic catch. Is this a bug, or am I doing something wrong?
#include <iostream>
#include "cppunit/Test.h"
#include "cppunit/extensions/HelperMacros.h"
using namespace std;
void throwException()
{
throw new SimpleException("Hey an exception");
}
public:
void setUp()
{
}
void tearDown()
{
}
void testOne ()
{
try
{
// If throwException is commented out I get "Should have thrown..."
// If left in I get "Message:caught unknown exception" not ex.getMessage()
throwException();
CPPUNIT_FAIL("Should have thrown an Exception before here");
}
catch (SimpleException ex)
{
CPPUNIT_FAIL(ex.getMessage());
}
}
Hi
Here is an example of my problem. I am running thhis inside Eclispe 2.1.1 using the CPPUnit Plugin. If I comment ou the call o throwException() I get the expected CPP_FAIL. If I catch the exception it does not execute the CPP_FAIL, but uses a generic catch. Is this a bug, or am I doing something wrong?
#include <iostream>
#include "cppunit/Test.h"
#include "cppunit/extensions/HelperMacros.h"
using namespace std;
class SimpleException
{
private:
char*message;
public:
SimpleException(char *msg)
{
message = msg;
}
char *getMessage()
{
return message;
}
};
class CrashTest: public CppUnit::TestFixture {
private:
void throwException()
{
throw new SimpleException("Hey an exception");
}
public:
void setUp()
{
}
void tearDown()
{
}
void testOne ()
{
try
{
// If throwException is commented out I get "Should have thrown..."
// If left in I get "Message:caught unknown exception" not ex.getMessage()
throwException();
CPPUNIT_FAIL("Should have thrown an Exception before here");
}
catch (SimpleException ex)
{
CPPUNIT_FAIL(ex.getMessage());
}
}
CPPUNIT_TEST_SUITE(CrashTest);
CPPUNIT_TEST(testOne);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(CrashTest);
You throw an exception as pointer type of SimpleException,
so you shoud code catch block as follow
catch (SimpleException *ex)
{
CPPUNIT_FAIL(ex->getMessage());
}
Or throw
throw SimpleException("Hey an exception");
Rigards,
Hisakuni