我有下面的代码,我用它来让一个用户静默登录
try {
result = await GoogleSignIn().signInSilently().catchError((x) {
print(x);
});
} catch (e) {
print(e);
}
如果用户无法静默登录,将会导致错误。
PlatformException (PlatformException(sign_in_required, com.google.android.gms.common.api.ApiException: 4: 4: , null))
我遇到的问题是,我似乎无法抓住例外。捕获错误或捕获块正在被击中。如何捕获此错误?
如果您使用< code > suppress errors = false ,则< code>catchError块实际上会被命中< br >尝试以下代码,并查看它在您的控制台上显示的内容。
result = await GoogleSignIn().signInSilently(suppressErrors: false).
catchError((x) {
print("inside catchError");
});
在您的方法中执行以下操作
try {
result = await GoogleSignIn().signInSilently(suppressErrors: false).catchError((x) {
print(x);
});
} catch (e) {
print(e);
}
默认情况下抑制错误=true
抑制要捕获的错误消息。
看源代码
SignInSilenly方法用于抑制错误消息,从而不会引发您想要捕获的异常。
从该方法的文档中:
/// When [suppressErrors] is set to `false` and an error occurred during sign in
/// returned Future completes with [PlatformException] whose `code` can be
/// either [kSignInRequiredError] (when there is no authenticated user) or
/// [kSignInFailedError] (when an unknown error occurred).
完整方法
/// Attempts to sign in a previously authenticated user without interaction.
///
/// Returned Future resolves to an instance of [GoogleSignInAccount] for a
/// successful sign in or `null` if there is no previously authenticated user.
/// Use [signIn] method to trigger interactive sign in process.
///
/// Authentication process is triggered only if there is no currently signed in
/// user (that is when `currentUser == null`), otherwise this method returns
/// a Future which resolves to the same user instance.
///
/// Re-authentication can be triggered only after [signOut] or [disconnect].
///
/// When [suppressErrors] is set to `false` and an error occurred during sign in
/// returned Future completes with [PlatformException] whose `code` can be
/// either [kSignInRequiredError] (when there is no authenticated user) or
/// [kSignInFailedError] (when an unknown error occurred).
Future<GoogleSignInAccount> signInSilently({bool suppressErrors = true}) {
final Future<GoogleSignInAccount> result = _addMethodCall('signInSilently');
if (suppressErrors) {
return result.catchError((dynamic _) => null);
}
return result;
}
参考文献
我正在从可能被压缩的服务器下载内容,所以我使用了我在不同地方找到的样板: 问题是,如果HTTPS请求因网络错误而失败,我有时会引发以下异常: 该“错误”事件处理程序未捕获异常。那么我如何捕获它,以便能够正确地清理文件并知道如何重试?
问题内容: 我在Python中构建了一个简短的url转换器引擎,并且看到大量的“管道破损”错误,并且很好奇在使用BaseHTTPServer类时如何最好地捕获它。这不是全部代码,但可以让您大致了解我目前正在做什么: 该代码本身运行良好,但是在生产中几乎立即开始引发错误: 这些错误的大部分似乎源于在调用send_header()方法时遇到的问题,其中我要写的是: 所以我很好奇在我的代码中尝试捕获此I
问题内容: 我正在使用PHP函数将数据从本地计算机发布到Web服务器。我的代码如下: 不幸的是,我无法捕获任何错误,例如404、500或网络故障。那么,我如何得知数据没有发布到远程或从远程检索呢? 问题答案: 您可以使用该功能检测是否有错误。例如:
问题内容: 我正在尝试在我的一个课程中实现PHP5的类型提示, 正确用法: 产生错误: 可捕获的致命错误:传递给ClassA :: method_a()的参数1必须是ClassB的实例,给定ClassWrong的实例… 是否有可能捕获到该错误(因为它说“可捕获”)?如果是的话,如何? 问题答案: 更新:这不再是php 7中可捕获的致命错误。相反,抛出了“异常”。不是从Exception而是Erro
问题内容: 我正在研究启动多个进程和数据库连接的python脚本。我不时地想用信号杀死脚本,我想进行一些清理。 在Perl中,我可以这样做: 如何在Python中做类似的事情? 问题答案: 用以下方式注册你的处理程序: 代码改编自此处。
本文向大家介绍React中在哪捕获错误?相关面试题,主要包含被问及React中在哪捕获错误?时的应答技巧和注意事项,需要的朋友参考一下 在react 15 极其以前的版本中,组件内的UI异常将中断组件内部状态,导致下一次渲染时触发隐藏异常。React并未提供友好的异常捕获和处理方式,一旦发生异常,应用将不能很好的运行。而React 16版本有所改进。 组件内异常,也就是异常边界组件能够捕获的异常,