如何在Flutter(`beacon_broadcast`库)中捕获错误?常规方法不适用于此库 [英] How do I catch an error in Flutter (`beacon_broadcast` library)? Conventional methods don't work for this library

查看:92
本文介绍了如何在Flutter(`beacon_broadcast`库)中捕获错误?常规方法不适用于此库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动信标时,我正在使用名为 beacon_broadcast 的库广播,它在控制台中输出一个错误,但是我无法捕获它( try .catchError ,并使用 .then 不起作用).

I am using a library called beacon_broadcast when I start the beacon broadcast, it outputs an error in the console, but I'm not able to catch it (try, .catchError, and using .then doesn't work).

控制台输出:

D/BeaconParser( 7318): Parsing beacon layout: blah_blah_blah
D/BluetoothAdapter( 7318): isLeEnabled(): ON
D/BluetoothAdapter( 7318): isLeEnabled(): ON
E/BeaconTransmitter( 7318): Advertisement start failed, code: 2

错误代码 2 表示广告位不可用.

Error code 2 means advertising slot not available.

我认为不需要为此显示源代码,因为这似乎不是我的代码有问题,而是有关在特定情况下如何执行操作的问题.

I do not think that I need to show my source code for this, since this does not seem to be a problem with my code, but rather a question about how to do something under specific circumstances.

推荐答案

检查您的try子句是否完全包装了负责该错误的代码部分,但我怀疑这不是您现在可以解决的问题.

Check if your try clause fully wraps the portion of code responsible for the error but I suspect that this is not something which you can solve now.

看一下库的存储库,我可以看到它首先需要处理平台特定代码(在本例中为Android/iOS/Web)中发生的错误,然后再处理Flutter.特别是,错误应从平台传播到Flutter,以让他处理并最终引发异常.有时开发人员会忘记这些检查,这就是为什么您不能直接从dart处理异常的原因.

Looking at the library's repository I can see that it needs to handle first the errors that occur in platform-specific code (in this case Android/iOS/Web) and then that concern with Flutter. In particular, the error should propagate from the platform to Flutter to let him handle and eventually raise the exception. Sometimes developers forget these checks and this is why you cannot handle the exception directly from dart.

这篇关于如何在Flutter(`beacon_broadcast`库)中捕获错误?常规方法不适用于此库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆