gpt4 book ai didi

flutter - 如何捕捉 flutter 中的致命异常

转载 作者:行者123 更新时间:2023-12-03 04:48:32 24 4
gpt4 key购买 nike

我从android抛出了以下异常(或者可以从ios抛出,这没有关系),并且我无法捕获它以避免应用崩溃。有解决方案吗?

  > [ +276 ms] E/AndroidRuntime( 9658): FATAL EXCEPTION: Thread-2 [       
> ] E/AndroidRuntime( 9658): Process: com.example.myonpu, PID: 9658 [
> ] E/AndroidRuntime( 9658):
> com.microsoft.identity.client.exception.MsalClientException:
> Connection is not available to refresh token [ ]
> E/AndroidRuntime( 9658): at
> com.microsoft.identity.client.internal.controllers.MsalExceptionAdapter.msalExceptionFromBaseException(MsalExceptionAdapter.java:49)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.client.PublicClientApplication$9.onError(PublicClientApplication.java:1621)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.common.internal.controllers.ApiDispatcher$4$1.run(ApiDispatcher.java:424)
> [ ] E/AndroidRuntime( 9658): at
> android.os.Handler.handleCallback(Handler.java:751) [ ]
> E/AndroidRuntime( 9658): at
> android.os.Handler.dispatchMessage(Handler.java:95) [ ]
> E/AndroidRuntime( 9658): at android.os.Looper.loop(Looper.java:154) [
> ] E/AndroidRuntime( 9658): at
> android.app.ActivityThread.main(ActivityThread.java:6682) [ ]
> E/AndroidRuntime( 9658): at java.lang.reflect.Method.invoke(Native
> Method) [ ] E/AndroidRuntime( 9658): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
> [ ] E/AndroidRuntime( 9658): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) [
> ] E/AndroidRuntime( 9658): Caused by:
> com.microsoft.identity.common.exception.ClientException: Connection is
> not available to refresh token [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.common.adal.internal.net.HttpWebRequest.throwIfNetworkNotAvailable(HttpWebRequest.java:201)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.common.internal.controllers.BaseController.performSilentTokenRequest(BaseController.java:328)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.common.internal.controllers.BaseController.renewAccessToken(BaseController.java:204)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.client.internal.controllers.LocalMSALController.acquireTokenSilent(LocalMSALController.java:252)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.common.internal.controllers.TokenCommand.execute(TokenCommand.java:89)
> [ ] E/AndroidRuntime( 9658): at
> com.microsoft.identity.common.internal.controllers.ApiDispatcher$4.run(ApiDispatcher.java:401)
> [ ] E/AndroidRuntime( 9658): at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
> [ ] E/AndroidRuntime( 9658): at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
> [ ] E/AndroidRuntime( 9658): at
> java.lang.Thread.run(Thread.java:762)

我不必捕获这个异常,而要捕获这样的“致命异常”。我尝试了try / catch和catchError for Future,但无能为力。

还尝试了FlutterError.onError这样:
mymethod() async{
await methodWhichCanThrowException();
FlutterError.onError = (details) {
FlutterError.dumpErrorToConsole(details);
};
...
}

如果可以帮助的话,我使用的是msal_flutter软件包 https://github.com/moodio/msal-flutter

最佳答案

您可以使用catchError()的默认方法flutter

mymethod() async{
await methodWhichCanThrowException().catchError((e)=> print(e.toString());
...
}

关于flutter - 如何捕捉 flutter 中的致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61825700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com