Skip to content

Commit

Permalink
add exception instruction
Browse files Browse the repository at this point in the history
Signed-off-by: howe <[email protected]>
  • Loading branch information
hzhyhx1117 authored and pymumu committed Nov 26, 2021
1 parent 75037a9 commit 8e210cf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions develop/debug/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ModelBox提供了多种调试方法,包含了业务运行,性能,和代码
|代码调试|代码级别的调试方法,主要使用现有的调试工具,IDE进行调试。|[指导](code-debug.md)|
|运行调试|使用运行日志,业务代码使用log类函数打印相关的日志。|[指导](log.md)|
|性能调试|对图的执行进行数据打点,并输出甘特图供性能分析调试。|[指导](profiling.md)|
|异常配置|对自定义flowunit产生的异常捕捉|[指导](exception.md)|
55 changes: 55 additions & 0 deletions develop/debug/exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 异常处理

开发者在运行流程图和开发流程图的过程当中,需要针对flowunit的情况返回异常,能够可以在其他业务流程中捕获当前异常进行自定义处理,modelbox即可提供该场景下异常捕获处理的能力

## 异常处理样例

+ 在自定义的flowunit当中,只需要在process处理过程当中针对需要处理的异常情况返回Status状态,如下例所示

```c++
Status Example::Process(std::shared_ptr<DataContext> data_ctx) {
if (exception) {
return {STATUS_FAULT, "the desc you want to catch."};
}
}
```
+ 在自定义的需要捕获的flowunit当中,需要做如下两件事:
1. 定义该flowunit的描述属性为ExceptionVisible(true)
```c++
MODELBOX_FLOWUNIT(ExampleFlowUnit, desc) {
...
desc.SetExceptionVisible(true);
} // 若为c++ flowunit
```

```toml
exception_visible = true # 若为python, 则在定义python的toml配置文件当中
```

1. 在获取flowunit的process当中获取exception error.

```c++
Status GetException::Process(std::shared_ptr<DataContext> data_ctx) {
if (data_ctx->HasError()) {
auto exception = data_ctx->GetError();
auto exception_desc = exception->GetDesc();
MBLOG_ERROR << "error is: " << exception_desc;
}
} // exception_desc 即为 "the desc you want to catch"
```
```python
def process(self, data_ctx):
if data_ctx.has_error():
exception = data_ctx.get_error()
exception_desc = exception.get_description()
print("error is: " + exception_desc)
# exception_desc 即为 "the desc you want to catch"
```

## 异常使用注意事项

+ 不要在if-else、loop当中以及拆分合并的flowunit中捕获异常

0 comments on commit 8e210cf

Please sign in to comment.