Hi,
I guess, you are on some unix ? You need to build your program with the
same compiler version as OOo has been built with. Not doing this
typically breaks exception handling, because you get incompatible stdc++
libraries into your process.
Bye,
Joerg
Pierre-André wrote:
Hello,
While trying to code, I am not able to catch Exceptions, not even standrard
exceptions...
In standard C++, this works :
#include <exception>
#include <iostream>
using namespace std;
class MyObj
{
public:
void func()
{
throw "Hello Exception";
}
};
int main()
{
try
{
MyObj o;
o.func();
}
catch( const char* e )
{
cout << e << endl;
}
}
But when compiling OpenOffice code, it does not :
// cpp file.
#include <iostream>
#include <exception>
#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
// Some other includes
#include <com/sun/star/uno/XNamingService.hpp>
#include <com/sun/star/connection/XConnector.hpp>
// Bad
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::bridge;
using namespace com::sun::star::frame;
using namespace com::sun::star::text;
using namespace rtl;
using namespace cppu;
using namespace std;
class MyObj
{
public:
void func()
{
cout << "Here we throwwwww !" << endl;
throw "Out of range";
}
};
// functions from an other object.
UnoConnect::UnoConnect()
{
MyObj m;
try
{
m.func();
}
catch (char * str)
{
cout << "Exception: " << str << endl;
}
}
Here is the result :
$ ./main
Here we throwwwww !
terminate called after throwing an instance of 'char const*'
Abandon
That means that the exception is not cought... But why is that exception not
cought ? Why is the terminate function called ?
When using the examples from the SDK, it is the same. You can try it with the
officeConnect example in the sdk
[OpenOffice.org2.0_SDK/examples/DevelopersGuide/ProfUNO/CppBinding/] if you
do not launch the office in listening mode. It throws an exception which
sould be cacth by the following piece of code :
catch( Exception &e )
{
OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
printf( "Error: %s\n", o.pData->buffer );
...
}
Which sould print something like :
Error: <some Data from the buffer>
but prints :
terminate called after throwing an instance of
'com::sun::star::connection::NoConnectException'
Any idea, where the problem comes from ?
Regards,
Pierre-André
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]