简体   繁体   English

未处理的异常:SocketException flutter

[英]Unhandled Exception: SocketException flutter

The goal is to get website from email.目标是从 email 获取网站。 I want to catch Socket Exceptions in a try Catch statement, but the following error wasn't caught and no print statement.我想在 try Catch 语句中捕获 Socket 异常,但是没有捕获到以下错误并且没有打印语句。

[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: SocketException: Failed host lookup: 'subdomain.domain.com' (OS Error: nodename nor servname provided, or not known, errno = 8). [VERBOSE-2:ui_dart_state.cc(177)] 未处理的异常:SocketException:主机查找失败:'subdomain.domain.com'(操作系统错误:提供节点名或服务名,或未知,errno = 8)。

Following the flutter documentation here and here按照此处此处的 flutter 文档

here is my code.这是我的代码。

import 'package:http/http.dart' as http;

Future<void> getWebsite(email) async {
    try {
      // get domain from email
      String _dom = new RegExp(r"(?<=[@]).+").stringMatch(email);
      // Get response status code from url
      final response = await http.get("https://$_dom");
      // Set Domain
      response.statusCode == 200 ? setDomain("https://$_dom") : setDomain(null);
    } on SocketException catch (_) {
      print("socket error");
    } on HttpException catch (_) {
      print("http error");
    } on FormatException catch (_) {
      print("format exception");
    } catch (e) {
      print("any exception");
    }
}

Here is the result of flutter doctor -v这是 flutter 医生 -v 的结果

[✓] Flutter (Channel master, 1.22.0-10.0.pre.153, on Mac OS X 10.15.5 19F101, locale en-US) • Flutter version 1.22.0-10.0.pre.153 at /Users/sean/developer/flutter • Framework revision 2e643651a9 (4 months ago), 2020-09-11 23:07:03 -0400 • Engine revision 16b900b63e • Dart version 2.10.0 (build 2.10.0-117.0.dev) [✓] Flutter(通道主机,1.22.0-10.0.pre.153,在 Mac OS X 10.15.5 19F101 上,语言环境 en-US) • Flutter 版本 1.22.0-10.0.pre.153 在 /sUserpre.0//sean。开发人员/颤振 • 框架修订版 2e643651a9(4 个月前),2020-09-11 23:07:03 -0400 • 引擎修订版 16b900b63e • Dart 版本 2.10.0(内部版本 2.10.0-117.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc1) • Android SDK at /Users/sean/Library/Android/sdk • Platform android-29, build-tools 30.0.0-rc1 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) • All Android licenses accepted. [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc1) • Android SDK at /Users/sean/Library/Android/sdk • Platform android-29, build-tools 30.0.0-rc1 • Java二进制文件位于:/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java 版本 OpenJDK 运行时环境(内部版本 1.8.0_212-release-1586-b4-5784211) • 接受所有 ZE84E30B9390CDB64DB6DB2C9AB8 许可证。

[✓] Xcode - develop for iOS and macOS (Xcode 11.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.3, Build version 11C29 • CocoaPods version 1.9.1 [✓] Xcode - develop for iOS and macOS (Xcode 11.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.3, Build version 11C29 • CocoaPods version 1.9.1

[✓] Android Studio (version 3.6) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 45.1.1 • Dart plugin version 192.7761 • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) [✓] Android Studio (version 3.6) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 45.1.1 • Dart plugin version 192.7761 • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586- b4-5784211)

[✓] VS Code (version 1.52.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.18.0 [✓] VS Code(版本 1.52.1) • /Applications/Visual Studio Code.app/Contents 中的 VS Code • Flutter 扩展版本 3.18.0

[✓] Connected device (1 available) [✓] 连接设备(1 个可用)
• iPhone 11 Pro (mobile) • E280A6FB-4AF7-4409-B79E-FA4E652C4FE0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator) • iPhone 11 Pro(移动) • E280A6FB-4AF7-4409-B79E-FA4E652C4FE0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3(模拟器)

• No issues found! • 未发现任何问题!

Here is what I see in the console这是我在控制台中看到的

Launching lib/main.dart on iPhone 11 Pro in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                           552.8s
Waiting for iPhone 11 Pro to report its views...
Debug service listening on ws://127.0.0.1:58043/ZgdnQH-v_BY=/ws
Syncing files to device iPhone 11 Pro...
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: SocketException: Failed host lookup: 'av.abbott.com' (OS Error: nodename nor servname provided, or not known, errno = 8)
#0      _NativeSocket.lookup.<anonymous closure> (dart:io-patch/socket_patch.dart:502:9)
#1      _rootRunUnary (dart:async/zone.dart:1198:47)
#2      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#3      _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#5      Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#6      Future._completeWithValue (dart:async/future_impl.dart:529:5)
#7      Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#8      _rootRun (dart:async/zone.dart:1190:13)
#9      _CustomZone.run (dart:async/zone.dart:1093:19)
#10     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#11     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:as<…>

I changed to stable channel which fixed the issue.我更改为解决问题的稳定频道。

https://flutter.dev/docs/development/tools/sdk/upgrading#switching-flutter-channels https://flutter.dev/docs/development/tools/sdk/upgrading#switching-flutter-channels

flutter channel stable flutter通道稳定

flutter upgrade flutter升级

get this exception when user is internet connection or slow or off.当用户连接互联网或速度慢或关闭时,会出现此异常。 so please check device connection所以请检查设备连接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter - 未处理的异常:SocketException: - Flutter - Unhandled Exception: SocketException: Flutter 未处理的异常:SocketException:操作系统错误:连接被拒绝,errno = 111 - Flutter Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111 flutter:未处理的异常:SocketException:操作系统错误:没有到主机的路由, - flutter: Unhandled Exception: SocketException: OS Error: No route to host, Flutter 未处理异常:SocketException:操作系统错误:损坏 pipe,errno = 32,地址 = 10.0.2.2,端口 = 51420 - Flutter Unhandled Exception: SocketException: OS Error: Broken pipe, errno = 32, address = 10.0.2.2, port = 51420 E/flutter (8084): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:SocketException:操作系统错误:连接被拒绝 - E/flutter ( 8084): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection refused 在 Flutter 中捕获未处理的异常 - Catching unhandled exception in Flutter flutter 中未处理的异常 - unhandled exception in flutter Flutter - 未处理的异常 - Flutter - Unhandled exception 未处理的异常:SocketException:操作系统错误:连接超时,errno = 110,地址 = api.generaliot.in,端口 = 45700 flutter - Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = api.generaliot.in, port = 45700 flutter 未处理的异常 - Flutter - Unhandled exception - Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM