对Unity3d C#手动处理异常产生

System.AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(_OnUnresolvedExceptionHandler);

Application.RegisterLogCallback(_OnDebugLogCallbackHandler);//接手处理Log,在回调方法_OnDebugLogCallbackHandler中进行人工处理

借用Crittercism中的回调代码演示样例:        

static private void _OnDebugLogCallbackHandler(string name, string stack, LogType type)
{
#if (UNITY_ANDROID && !UNITY_EDITOR) || FORCE_DEBUG
if(LogType.Assert != type && LogType.Exception != type) { return; }
if(mCrittercismsPlugin == null || _IsPluginInited == false) { return; }

try
{
mCrittercismsPlugin.CallStatic("LogUnhandledException", name, name, stack);

}catch(System.Exception e) { CLog(e.Message); }
#endif
}


ps.能够中和回调方法,说log写入到文件中的信息,或发送给后台的哦~~

版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4796722.html