You can't catch all other exceptions in other plugins. Unity does that in the background and Unity gives you API to receive the exceptions it caught:
Newer version of Unity:
void OnEnable()
{
Application.logMessageReceived += LogCallback;
}
//Called when there is an exception
void LogCallback(string condition, string stackTrace, LogType type)
{
//Send Email
}
void OnDisable()
{
Application.logMessageReceived -= LogCallback;
}
Older version of Unity:
void OnEnable()
{
Application.RegisterLogCallback(LogCallback);
}
//Called when there is an exception
void LogCallback(string condition, string stackTrace, LogType type)
{
//Send Email
}
void OnDisable()
{
Application.RegisterLogCallback(null);
}
There is also logMessageReceivedThreaded
.
EDIT:
Stacktrace issue:
If the stackTrace
parameter is empty then you can use the System.Diagnostics.StackTrace
class to manually retrieve the stacktrace yourself while still inside the LogCallback
function. For example,
void LogCallback(string condition, string stackTrace, LogType type)
{
//Send Email
System.Diagnostics.StackTrace sTrace = new System.Diagnostics.StackTrace();
Debug.Log(sTrace.ToString());
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…