问题
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