NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[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 ```