Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception unity firebase捕获异常错误_Exception_Unity3d_Firebase_Try Catch_Storage - Fatal编程技术网

Exception unity 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) {

你好

我们正在使用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());
        }
    });
在上面的示例中,我们希望捕获任务异常并打印我们自己的错误,但没有相关文档

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;
    }