Other versions: 1.0

Change picture:

Choose file:

Exception Handling in Dao


Dao exceptions are organized into hierarchal structured classes. The base class is Exception ,
class  Exception
{
    routine  Exception(  content=''){  Content  =  content  }
    protected
        var  Rout  =  '';
        var  File  =  '';
        var  FromLine  =  0;
        var  ToLine  =  0;
    public
        var  Name    =  'Exception';
        var  Content  :  any  =  'undefined exception';
}
Currently supported classes are the following:
Class Exception Type
Exception Any
Exception.None None
Exception.Any Any or none
Exception.Error Any error
Exception.Warning Any warning
Exception.Error.Field invalid field accessing
Exception.Error.Field.NotExist field not exist
Exception.Error.Field.NotPermit field not permit
Exception.Error.Float invalid floating point operation
Exception.Error.Float.DivByZero division by zero
Exception.Error.Float.OverFlow floating point overflow
Exception.Error.Float.UnderFlow floating point underflow
Exception.Error.Index invalid index
Exception.Error.Index.OutOfRange index out of range
Exception.Error.Key invalid key
Exception.Error.Key.NotExist key not exist
Exception.Error.Param invalid parameter list for the call
Exception.Error.Syntax invalid syntax
Exception.Error.Type invalid variable type for the operation
Exception.Error.Value invalid variable value for the operation
New exception classes can be derived from the above classes.

Any running time error will raise a proper exception instance. User-defined exception can be raised by using raise statement. Exceptions can be rescued by a block of code after a rescue statement The exception handling syntax is the following:
stmt_tryrescue  ::=
     'try''{'  stmt_block
     {'}''rescue'['('  expr  ')']'{'  stmt_block  }*
     '}'
where expr is a list of exception class(es). If there is no expr following rescue , any exception will be rescued. There can be multiple rescue statements in a try-rescue block. The raised exceptions will be checked against the exception classes presented in each of the rescue statement, if there is a matching, the corresponding code block is executed, and the rescued exceptions can be accessed in a global list named exceptions . In the same try-rescue block different rescue statements can be used to handle different exceptions.

If all rescue statements have been tried and there is still un-rescued exception(s), the current function is aborted and the exceptions(s) is raised to its caller, if there is; otherwise, the program is aborted with the values of the un-rescued exceptions printed out. In a rescue statement, one may modify exection condition, and use retry to invoke the codes in try block.

Examples,
try{
     raise  Exception.Error("error test"),  Exception.Warning("warning test"),
     Exception("exception");
}rescue(  Exception.Error,  Exception.Warning  ){
     stdio.println(  exceptions  );
}rescue{
     stdio.println("rescued");
}

view count 562 times
created at 2009-02-28, 16:43 GMT
modified at 2009-09-18, 06:41 GMT

12 3
456789 10
111213141516 17
181920212223 24
2526272829 30 31

fu: Many thanks (Jul.04,04:29)

klabim: fixed Hi, great, now my test works now :- ). (Jun.30,17:51)

Nightwalker: Few suggestions (Jul.03,14:37)

This site is powered by Dao
Copyright (C) 2009,2010, daovm.net.
Webmaster: admin@daovm.net