unity firebase 捕获异常错误
unity firebase catch exception errors
美好的一天!
我们正在使用 unity 来处理 firebase。我们参考了 firebase 统一指南。我们试图从不存在的存储中下载文件,并返回了一个错误,指出超过了重试限制。我们想捕获此错误并显示我们自定义的错误消息,因为重试限制超出的默认异常非常长。这是我们打印异常的代码示例。
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());
}
});
在上面的示例中,我们想捕获任务异常并打印我们自己的错误,但没有相关文档。
例如
if (ErrorRetryLimitExceeded)
Debug.Log("Retry Limit Exceeded");
else if (ErrorCanceled )
Debug.Log("Download was canceled by user");
另外,firebase 现在有 Firebase Authorization for Unity 的异常参考吗?
谢谢!
这里是 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;
}
美好的一天!
我们正在使用 unity 来处理 firebase。我们参考了 firebase 统一指南。我们试图从不存在的存储中下载文件,并返回了一个错误,指出超过了重试限制。我们想捕获此错误并显示我们自定义的错误消息,因为重试限制超出的默认异常非常长。这是我们打印异常的代码示例。
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());
}
});
在上面的示例中,我们想捕获任务异常并打印我们自己的错误,但没有相关文档。
例如
if (ErrorRetryLimitExceeded)
Debug.Log("Retry Limit Exceeded");
else if (ErrorCanceled )
Debug.Log("Download was canceled by user");
另外,firebase 现在有 Firebase Authorization for Unity 的异常参考吗?
谢谢!
这里是 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;
}