| Basic Types | Enum Types | Object Types | Array Types | Interface Types | Exception Types | Member Types | Method Types | Namespace Types | Foreign Types |
Exception types used to signal errors or other
exeptional conditions.
The type system of ACDK follows the Java modell.
The base class of all exeptions is the class acdk::lang::Throwable.
It the same interface and functionallity, like the Java class java.lang.Throwable.
ACDK Exceptions are a little bit different to ordinary
ACDK classes:
// ...
// declare the MyException, derived from Exception
// defines also RMyException
ACDK_DECL_THROWABLE(MyException, Exception);
// alternativelly fully qualified:
ACDK_DECL_THROWABLE_FQ(MyException, acdk::lang::, Exception);
class MyException
: extends acdk::lang::Exception
{
ACDK_WITH_METAINFO(MyException) // optional, for class information see Metainfo
public:
MyException() : Exception() {}
MyException(RString what) : Exception(what) {}
};
|
It is import to use the ACDK_DECL_THROWABLE or ACDK_DECL_THROWABLE_FQ macros
to declare the exception, becuase this enables structured - based on the
class derivation - exception handling.
To throw an exception the best way is to use one the
THROW macros:
...
// throw exception with 0 arguments
THROW0(Exception);
// throw exception with 1 argument
THROW1(Error, "An general Error");
// throw fully qualified (namespace) exception with 1 argument
THROW1_FQ(acdk::io::, IOException, "File not open");
|
Exception are thrown and catched as reference. This is the
reason why following constructs are not working the ACDK way:
// NOT OK, because throws 'Error'
throw Error("An general Error");
// NOT OK, because throws 'Error*'
throw new Error("An general Error");
// OK, because throws 'RError'
THROW1(Error, "An general Error");
// OK, because throws 'RError'
// but not recommended, because may
// not be handled by Script debugger
throw RError(new Error("An general Error"));
|
Exception can be catched following way:
void foo()
{
try {
} catch (acdk::io::RIOException ex) {
// handle here type of IOException.
} catch (RThrowable ex) {
// handle all other ACDK exceptions
}
/* DONT DO THAT
otherwise Nullpointer exception will not handled properly
} catch (...) {
// this are not ACDK exception
// for example std::exception, if you use STL
}
*/
}
|
See also: Exception declaration.
See also: Throwable.
|