https://stackoverflow.com/questions/32810051/cannot-catch-socketexception/32810079#32810079

https://github.com/dart-lang/sdk/issues/25518

2
 

Asynchronous errors can't be caught using try/catch(https://www.dartlang.org/docs/tutorials/futures/) at least unless you are using async/await(https://www.dartlang.org/articles/await-async/)

See also https://github.com/dart-lang/sdk/issues/24278

You can use the done future on the WebSocket object to get that error, e.g.:

import 'dart:async';
import 'dart:io'; main() async {
// Connect to a web socket.
WebSocket socket = await WebSocket.connect('ws://echo.websocket.org'); // Setup listening.
socket.listen((message) {
print('message: $message');
}, onError: (error) {
print('error: $error');
}, onDone: () {
print('socket closed.');
}, cancelOnError: true); // Add message, and then an error.
socket.add('echo!');
socket.addError(new Exception('error!')); // Wait for the socket to close.
try {
await socket.done;
print('WebSocket donw');
} catch (error) {
print('WebScoket done with error $error');
}
}

  

I get your point, but I don't understand why this is an asynchronous error. I mean, you get this error before starting to actually asynchronously listen to requests, right? – Alexandr Sep 27 '15 at 16:41
1
HttpServer.bind() is already async (returns a Future<HttpServer>) – Günter Zöchbauer Sep 27 '15 at 16:43
You are right, Gunter. Thank you for this! – Alexandr Sep 28 '15 at 5:35

最新文章

  1. iOS 开发快速导引:iOS 程序框架【草】
  2. Codeigniter
  3. Python数据类型之“集合(Sets)与映射(Mapping)”
  4. Java Data Type
  5. 类似input框内最右边添加图标,有清空功能
  6. hdu 5154 Harry and Magical Computer
  7. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) A. Slime Combining 水题
  8. json 转 javaBean
  9. MVC小系列(二)【Razor 模板引擎】
  10. 【微信公众号】验证用户OpenID是否关注某个公众号
  11. 理解Servlet及其对象
  12. [TensorFlow] Basic Usage
  13. JPA Advanced Mappings(映射)
  14. 网络基础Cisco路由交换四
  15. C#之AES256位加密解密
  16. ASP.NET Core中的Startup类
  17. C语言程序设计II—第二周教学
  18. windows版 Java调用人脸识别离线sdk
  19. codecombat js
  20. Python入门基础学习 一

热门文章

  1. java 中利用反射机制获取和设置实体类的属性值
  2. 作业——10 分布式文件系统HDFS 练习
  3. unused function warning message(转)
  4. 爬虫的正则表达式re模块
  5. [LeetCode] 77. Combinations 全组合
  6. [LeetCode] 250. Count Univalue Subtrees 计算唯一值子树的个数
  7. mysql instr()函数
  8. Kubernetes 配置管理 ConfigMap(十二)
  9. 乐橙平台大华监控Android端实时预览播放
  10. scrapy爬虫,cmd中执行日志中显示了爬取的内容,但是运行时隐藏日志后(运行命令后添加--nolog),就没有输出结果了