Other versions: 1.0

Change picture:

Choose file:

道语言异常处理


道异常类被组织为树形结构,其基类是 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';
}
目前支持的类包括:
异常类型
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
从以上类可以派生出新的异常类。

任何运行时错误将抛出异常类实例。 程序也可在任何地方使用raise语句抛出异常类实例。 被抛出的异常可由rescue语句扑获,然后进行处理, 相关语法是:
stmt_tryrescue  ::=
     'try''{'  stmt_block
     {'}''rescue'['('  expr  ')']'{'  stmt_block  }*
     '}'
这里expr可以为空,或是一个或多个异常类。 如果rescue后没有expr,所有异常都将被扑获。 每个try-rescue块里,可以有多个rescue语句, 每个rescue语句都将被检测是否可以扑获到异常, 如果扑获到了,相应的语句块将被执行, 并且被扑获的异常将可用全局变量exceptions列表访问。

如果所有rescue语句都被检测了,但还剩没有扑获的异常, 那么当前运行函数将中止,并将异常抛给起调用者。 如果当前函数没有调用者,那么程序将被中止, 并打印异常信息。 在一个rescue语句块里,在修改某些运行条件后,retry可用来重新尝试 执行try语句块里的代码。

例子,
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 359 times
created at 2009-03-02, 17:07 GMT
modified at 2009-09-18, 06:40 GMT

123 4
56789 10 11
121314151617 18
192021222324 25
2627282930

fu: Fixed and updated There was a minor bug in storing returned value in the DaoVmProcess structure. Now it is fixed and up ... (Sep.07,23:43)

klabim: ... Ok, I found it. It can be so easy by reading the documentation :- ). I have overseen the keyword glob ... (Aug.21,18:09)

klabim: returning a string from function to c++ code! Hi, I run in some trouble while calling a dao function from the c++ code. The dao function should re ... (Sep.07,19:44)

klabim: sharing vars between scripts Hi, how can I share a variable between 2 scripts in an embedded environment? For example: script 1: ... (Aug.21,17:55)

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