| References | Casting | Arrays | Import | instanceof | Package | Synchronization | Throwable | finally | Dangerous | Stack | String |
In ACDK Exeption, handling is implemented as a standard C++ mechanism with some
extionsion.
All Classes in Java and ACDK, which can be thrown are derived by
Throwable.
// Java
void foo() throws Exception
{
throw new Exception("A Message");
}
|
// C++ / acdk
void foo() // no declaration of throwing classes here
{
throw RException(new Exception("A Message"));
// or alternatally with extended debugging features
THROW1(Exception, "A Message");
}
|
Unfortunately, the 'new Exception()'-syntax can not be used.
Unlike Java, where all Classes are checked to declare them as possible thrown
exceptions during Compiletime, in C++ they are evaluated during
runtime. If an exception, which is declared in the method throw is not catched,
the process will be terminated.
Please refer also to:
Casting.
Finally.
Exception Types.
In a catch clause you may rethrow an exception:
try {
methodThrowsException();
} catch (RThrowable ex) {
throw ex; // this will throw only a RTrowable, not the original RExceptionType
THROW_INSTANCE(ex); // better, use meta info to throw the correct exception type
}
|
In case a method throws other exception than errors,
they should be declared in the method:
class AClass
{
public:
// C++: void foo() throw(RMyException, RMyOtherException, RThrowable);
// better to use a macro, because on some platforms
// the throw declaration is not supported by the compiler:
void foo() THROWS2(RMyException, RMyOtherException);
};
|
The THROWS declaration is also be used by the DMI-interface to unmarshal
and throw typed exception in remote/script invocation.
See also:
Throwable.
Exception declaration.
|