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

catch SocketException的更多相关文章

  1. ClientAbortException: java.net.SocketException: 断开的管道

    这次终于解决了 ClientAbortException ! [ERROR] [- ::] net.jweb.actions.CommonDiskAction - 系统异常 ClientAbortEx ...

  2. zookeeper源码分析之一服务端启动过程

    zookeeper简介 zookeeper是为分布式应用提供分布式协作服务的开源软件.它提供了一组简单的原子操作,分布式应用可以基于这些原子操作来实现更高层次的同步服务,配置维护,组管理和命名.zoo ...

  3. 简约之美Jodd-http--深入源码理解http协议

    Jodd 是一个开源的 Java 工具集, 包含一些实用的工具类和小型框架.简单,却很强大! jodd-http是一个轻巧的HTTP客户端.现在我们以一个简单的示例从源码层看看是如何实现的? Http ...

  4. Android—基于微信开放平台v3SDK,开发微信支付填坑。

    接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...

  5. 《连载 | 物联网框架ServerSuperIO教程》- 10.持续传输大块数据流的两种方式(如:文件)

    1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...

  6. 《连载 | 物联网框架ServerSuperIO教程》- 12.服务接口的开发,以及与云端双向交互

    1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...

  7. 从无到有实现登录功能以及thinkphp怎么配置数据库信息

    好开心,终于解决了.从学习android到现在写登录功能已经不是一次两次了,如今再写想着肯定是信手拈来,没有想到的是尽然折磨了我一天的时间才搞定它.唉...... 先来看几张截图,这次的登录跟以往的不 ...

  8. .net Socket 通信简单实例(初级入门)

    c/s控制台应用程序,Server.Client分别在两个项目中 服务端 using System; using System.Collections.Generic; using System.Li ...

  9. C#编写window服务,一步一步(1)

    Window服务是啥,这里就不废话了,如何用在哪里用也不废话了,这里我这篇文章只是详述了我在vs2012中创建window服务的经过,希望对你有所帮助. 另外:我在编写服务过程中参考了 Profess ...

随机推荐

  1. 集成了SSM框架的系统怎么做测试?

    1.首先在测试文件夹下新建一个测试基类BaseTest BaseTest中的代码如下: package wbl_ssm_blog.mapper; import org.junit.Test; impo ...

  2. np.meshgrid

  3. [转]详解Linux(centos7)下安装OpenSSL安装图文方法

    OpenSSL是一个开源的ssl技术,由于我需要使用php相关功能,需要获取https的文件所以必须安装这个东西了,下面我整理了两种关于OpenSSL安装配置方法. 安装环境:  操作系统:CentO ...

  4. NPOI导出EXCEL样式

    public void Export(DataRequest<ExportModel> request, DataResponse<dynamic> response) { t ...

  5. Spring cloud微服务安全实战-7-8ELK+SpringBoot环境搭建

    采集不可聚合的离散的.日志信息的e ELK是三个系统的简称 LogStash:用来做日志的收集.过滤.格式转换 Kibana:和普罗米修斯的grafana一个意思.主要用来展示数据. 用docker来 ...

  6. [LeetCode] 111. Minimum Depth of Binary Tree 二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  7. Apache软件基金会核心项目Tomcat的那些事

    Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选.今天就来为大家介绍一下关于T ...

  8. Dev c++编译报错

    https://blog.csdn.net/qq_37521610/article/details/87640513

  9. GAN代码实战

    batch normalization 1.BN算法,一般用在全连接或卷积神经网络中.可以增强整个神经网络的识别准确率以及增强模型训练过程中的收敛能力2.对于两套权重参数,例如(w1:0.01,w2: ...

  10. Fiddler如何切换hosts以及切换hosts的另一个神器SwithcHosts