我在 CORBA 中对自己的用户定义异常有一些问题。这是我非常简单的代码:
interface Interfface
{
exception myOwnException {};
void ffunction(in double arg) raises (myOwnException);
};
#include "Interfface.hh"
class Implementation : public POA_Interfface
{
public :
virtual void ffunction(double arg) throw (myOwnException);
};
#include "Implementation.h"
void Implementation::ffunction(double arg) throw (myOwnException)
{
arg ++;
throw (myOwnException);
}
当我编译 Implementation.cpp 时,它给了我一些错误(http://pastie.org/private/a22ikk09zkm9tqywn37w):
Implementation.cpp: In member function ‘virtual void Implementation::ffunction(double)’:
Implementation.cpp:5: error: ‘myOwnException’ was not declared in this scope
In file included from Implementation.cpp:1:
Implementation.h:6: error: expected type-specifier before ‘myOwnException’
Implementation.h:6: error: expected ‘)’ before ‘myOwnException’
Implementation.h:6: error: expected ‘;’ before ‘myOwnException’
Implementation.cpp:3: error: expected type-specifier before ‘myOwnException’
Implementation.cpp:3: error: expected ‘)’ before ‘myOwnException’
Implementation.cpp:3: error: expected initializer before ‘myOwnException’
这段代码有什么问题?还有一个问题:我如何在 Java 中做同样的事情?
这是我的代码:http ://speedy.sh/F5utX/user-defined-exception.tar 我在java中做了同样的事情(代码也在user-defined-exception.tar)但是java代码给了我这个:
Note: InterffacePOA.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.