How do I catch an error in Flutter (`beacon_broadcast` library)? Conventional methods don't work for this library

两盒软妹~` 提交于 2021-02-11 12:41:21

问题


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).

Console Output:

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

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/61215429/how-do-i-catch-an-error-in-flutter-beacon-broadcast-library-conventional-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!