Exception unity firebase捕获异常错误
你好 我们正在使用unity与firebase合作。我们参考了firebase统一指南。我们试图从不存在的存储中下载文件,但返回了一个超过重试限制的错误。我们希望捕获此错误并显示自定义错误消息,因为重试限制超出的默认异常非常长。下面是打印异常的代码示例Exception unity firebase捕获异常错误,exception,unity3d,firebase,try-catch,storage,Exception,Unity3d,Firebase,Try Catch,Storage,你好 我们正在使用unity与firebase合作。我们参考了firebase统一指南。我们试图从不存在的存储中下载文件,但返回了一个超过重试限制的错误。我们希望捕获此错误并显示自定义错误消息,因为重试限制超出的默认异常非常长。下面是打印异常的代码示例 imaginary_ref.GetBytesAsync (maxAllowedSize).ContinueWith (task => { if (task.IsFaulted || task.IsCanceled) {
imaginary_ref.GetBytesAsync (maxAllowedSize).ContinueWith (task => {
if (task.IsFaulted || task.IsCanceled) {
Debug.Log (task.Exception.ToString());
}
else if (task.IsCompleted) {
Debug.Log ("Successful download!");
} else{
Debug.Log (task.Exception.ToString());
}
});
在上面的示例中,我们希望捕获任务异常并打印我们自己的错误,但没有相关文档
前
firebase现在是否有Unity firebase授权的例外参考
谢谢 这里是Firebase开发者 是的,使用StorageException.ErrorCode的Firebase存储应该可以做到这一点
imaginary_ref.GetBytesAsync (maxAllowedSize).ContinueWith (task => {
if (task.IsFaulted || task.IsCanceled) {
AggregateException ex = task.Exception as AggregateException;
if (ex != null) {
StorageException inner = ex.InnerExceptions[0] as StorageException;
if (inner != null && inner.ErrorCode == StorageException.ErrorRetryLimitExceeded) {
Debug.Log ("retry failed!");
}
}
}
else if (task.IsCompleted) {
Debug.Log ("Successful download!");
}
});
这对我有用
public int HandleIsFaulted(Task t)
{
System.AggregateException ex = t.Exception as System.AggregateException;
if (ex != null)
{
Firebase.FirebaseException fbEx = null;
foreach (System.Exception e in ex.InnerExceptions)
{
fbEx = e as Firebase.FirebaseException;
if (fbEx != null)
{ break; }
if (e.InnerException != null)
{
Firebase.FirebaseException innerEx = e.InnerException as Firebase.FirebaseException;
if (innerEx != null)
{
fbEx = innerEx;
break;
}
}
}
if (fbEx != null)
{
Debug.LogWarning("Encountered a FirebaseException:" + fbEx.ErrorCode);
return fbEx.ErrorCode;
}
}
return -1;
}
谢谢,这对我帮助很大。我注意到我不能为FirebaseAuth这样做?FirebaseAuth有类似的功能吗?这对于Firebase auth来说是非常有用的答案-
public int HandleIsFaulted(Task t)
{
System.AggregateException ex = t.Exception as System.AggregateException;
if (ex != null)
{
Firebase.FirebaseException fbEx = null;
foreach (System.Exception e in ex.InnerExceptions)
{
fbEx = e as Firebase.FirebaseException;
if (fbEx != null)
{ break; }
if (e.InnerException != null)
{
Firebase.FirebaseException innerEx = e.InnerException as Firebase.FirebaseException;
if (innerEx != null)
{
fbEx = innerEx;
break;
}
}
}
if (fbEx != null)
{
Debug.LogWarning("Encountered a FirebaseException:" + fbEx.ErrorCode);
return fbEx.ErrorCode;
}
}
return -1;
}