因此,我已将Firebase Unity插件集成到我的Unity项目中。我遇到了一个问题,如果我没有连接到互联网,Firebase会在尝试获取数据库引用时抛出各种错误。在(Firebase.Database.FirebaseDatabase)database.GetReference(path)上调用以下错误。
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 :(得分:0)
try
{
YourCodeToCallFireBaseFunction(); // statements causing exception
}
catch( SocketException e1 ) //Specifically catch **SocketException**
{
// error handling code
}
finally
{
// statements to be executed
}