catch SocketException
https://stackoverflow.com/questions/32810051/cannot-catch-socketexception/32810079#32810079
https://github.com/dart-lang/sdk/issues/25518
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
donefuture on theWebSocketobject 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的更多相关文章
- ClientAbortException: java.net.SocketException: 断开的管道
这次终于解决了 ClientAbortException ! [ERROR] [- ::] net.jweb.actions.CommonDiskAction - 系统异常 ClientAbortEx ...
- zookeeper源码分析之一服务端启动过程
zookeeper简介 zookeeper是为分布式应用提供分布式协作服务的开源软件.它提供了一组简单的原子操作,分布式应用可以基于这些原子操作来实现更高层次的同步服务,配置维护,组管理和命名.zoo ...
- 简约之美Jodd-http--深入源码理解http协议
Jodd 是一个开源的 Java 工具集, 包含一些实用的工具类和小型框架.简单,却很强大! jodd-http是一个轻巧的HTTP客户端.现在我们以一个简单的示例从源码层看看是如何实现的? Http ...
- Android—基于微信开放平台v3SDK,开发微信支付填坑。
接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...
- 《连载 | 物联网框架ServerSuperIO教程》- 10.持续传输大块数据流的两种方式(如:文件)
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- 《连载 | 物联网框架ServerSuperIO教程》- 12.服务接口的开发,以及与云端双向交互
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- 从无到有实现登录功能以及thinkphp怎么配置数据库信息
好开心,终于解决了.从学习android到现在写登录功能已经不是一次两次了,如今再写想着肯定是信手拈来,没有想到的是尽然折磨了我一天的时间才搞定它.唉...... 先来看几张截图,这次的登录跟以往的不 ...
- .net Socket 通信简单实例(初级入门)
c/s控制台应用程序,Server.Client分别在两个项目中 服务端 using System; using System.Collections.Generic; using System.Li ...
- C#编写window服务,一步一步(1)
Window服务是啥,这里就不废话了,如何用在哪里用也不废话了,这里我这篇文章只是详述了我在vs2012中创建window服务的经过,希望对你有所帮助. 另外:我在编写服务过程中参考了 Profess ...
随机推荐
- 带状矩阵的存储(c++)
2 1 0 0 3 1 3 0 0 5 2 7 0 0 9 0 这个程序对于三对角矩阵都是有效的,为了精 ...
- 忘记zip密码咋办?python在手密码我有
整理资料时发现几个 zip 文件的密码忘记了,于是尝试用python暴力破解 首先是读取和解压zip文件,使用 zipfile 库 import zipfile z = zipfile.ZipFile ...
- uniapp - 微信公众号授权登录
[缘由] 采用uniapp进行微信小程序和微信公众号双版本开发:考虑到用户唯一性,我们后端确定了以“unionid”.作为唯一标识. 有的小伙伴估计也是刚入这坑,我就简单说一下步骤流程 [摸索] ...
- [转]C++ 使用 curl 进行 http 请求(GET、POST、Download)的封装
原文连接:https://www.cnblogs.com/oftenlin/p/9478067.html CommonTools.h /* * CommonTools.h * * Created ...
- Docker容器(六)——创建docker私有化仓库
docker私有化仓库是为了节约带宽(外网速度慢或者干脆不能连外网),以及自己定制系统. (1).环境 youxi1 192.168.5.101 docker私有化仓库 youxi2 192.168. ...
- 如何在LabWIndows/CVI中调用LabVIEW DLL
首先请参考官方的文档 http://digital.ni.com/public.nsf/websearch/70995EC2CA1B523386256DD4004F3DE6?OpenDocument ...
- EasyNVR摄像机网页直播之问题解决:Failed:SYSTEM\CurrentCont......\Application\EasyNVR_Service registry key already
背景分析 经常使用EasyNVR产品的用户都知道,作为音视频行业互联网直播产品,EasyNVR主要功能在于通过RTSP/ONvif协议,接入前端音视频采集设备,通过EasyNVR软硬件产品将拉取过来的 ...
- glob 遍历文件夹里面文件
var_dump(glob("*")); // 只会遍历当前文件夹层里面的,不会往里面扒 exit; array(9) { [0]=> string(16) "Ca ...
- [LeetCode] 139. Word Break 单词拆分
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...
- [LeetCode] 653. Two Sum IV - Input is a BST 两数之和之四 - 输入是二叉搜索树
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...