2017-08-28 65 views
0

因此,我已將Firebase Unity插件集成到Unity項目中。如果我沒有連接到互聯網,我遇到了一個問題,Firebase在嘗試獲取數據庫引用時會拋出各種錯誤。 (Firebase.Database.FirebaseDatabase)database.GetReference(path)上調用以下錯誤。如果沒有互聯網連接,無法啓動Unity + Firebase

01/02/0001 17:46:29 [Error] WebSocket: ws_0 - could not get ip address 
System.Net.Sockets.SocketException: No such host is known 
    at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename  unknown>:0 
    at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0 
    at Firebase.Database.Internal.TubeSock.WebSocket.GetIpAddress (System.String hostName) [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object) 
Firebase.FirebaseHandler:LogMessage(LogLevel, String) 
Firebase.Unity.UnityLoggingService:LogMessage(LogLevel, String) 
Firebase.Database.Internal.Logging.DefaultLogger:Error(String, String) 
Firebase.Database.Internal.Logging.DefaultLogger:OnLogMessage(Level, String, String, Int64) 

我該如何避免這種情況?

回答

0
try 
{ 
    YourCodeToCallFireBaseFunction(); // statements causing exception 
} 
catch(SocketException e1) //Specifically catch **SocketException** 
{ 
    // error handling code 
} 
finally 
{ 
    // statements to be executed 
} 
+0

我發現特定的行引發錯誤,但try catch塊不會捕獲異常。我認爲這是因爲異常被引入Firebase的內部庫或其他東西 –