This is NOT the latest version, which is available at: current

Change picture:

Choose file:

Exception Handling in Dao


Dao exceptions are organized into hierarchal structured classes. The base class is Exception ,
class  Exception(  content='')
{
    protected
        my  Rout  =  '';
        my  File  =  '';
        my  FromLine  =  0;
        my  ToLine  =  0;
    public
        my  Name    =  'Exception';
        my  Content  :  any  =  'undefined exception';
        if(  content  )  Content  =  content;
}
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 433 times
created at 2009-09-18, 06:38 GMT

123 4
56 78910 11
121314151617 18
192021222324 25
26272829

fu: ... I forgot to say something about the plan for the whole new year in my previous reply. Well, besides w ... (Jan.19,01:40)

fu: ... Happy new dragon year (which will start from this sunday)! Actually, it was a busy month (I wish th ... (Jan.18,22:46)

ybabel: What's the plan for the new year ? Hello 'vry budy :- ) happy new year (when is the new year for you Fu ?) I saw you come back and comm ... (Jan.18,18:59)

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