ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 异常 ``` throw FormatException('Expected at least 1 section'); throw 'Out of llamas!'; // 抛出任意的对象 try { throw FormatException("1111"); // throw "222"; } on Exception catch (e) { // 其他任何异常 print('Unknown exception: $e'); //1111 } catch (e) { // 没有指定的类型,处理所有异常 print('Something really unknown: $e'); // 222 } ``` ### 重新抛出异常 ``` try { dynamic foo = true; print(foo++); // Runtime error } catch (e) { print('misbehave() partially handled ${e.runtimeType}.'); rethrow; // Allow callers to see the exception. } ``` ### finally ``` try { throw "222"; } catch (e) { print('Something really unknown: $e'); } finally{ print("end"); //end } //output // Something really unknown: 222 //end ```