facebook twitter hatena line email

Unity/sentry/ログ

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

色々なログ

Exceptionをそのままthrow

void Start()
{
    Exec();
}
void Exec()
{
    throw new Exception("例外エラー1");
}

ログ

Stack Trace
System.Exception
例外エラー1
HogeProject/Assets/Scripts/ExceptionScene.cs in Exec at line 26:9
In App
HogeProject/Assets/Scripts/ExceptionScene.cs in Start at line 15:13

try-catchをせず、アプリに対してthrow Exceptionしてしまう。

Exceptionをtry-catchで取得したとき

try
{
    Exec();
}
catch (Exception e)
{
    Debug.LogError(e.Message + ":" + e.StackTrace);
}

ログ

例外エラー1:  at ExceptionScene.Exec () [0x00000] in HogeProject/Assets/Scripts/ExceptionScene.cs:26 
  at ExceptionScene.Start () [0x0000a] in HogeProjectAssets/Scripts/ExceptionScene.cs:15 

async内でexceptionを出す場合

void Start()
{
    try
    {
        Exec();
    }
    catch (Exception e)
    {
        Debug.LogError(e.Message + ":" + e.StackTrace);
    }
}
async void Exec()
{
    var result = await ExecUniTask();
    Debug.Log("Exec " + result);
}
async UniTask<float> ExecUniTask()
{
    await UniTask.Delay(1000);
    throw new Exception("例外エラー1");
    return 100f;
}

ログ

HogeProject/Assets/Scripts/ExceptionScene.cs in ExecUniTask at line 32:9
In App
Hoge/Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTask.Factory.cs in GetResult at line 255:17
In App
HogeProject/Assets/Scripts/ExceptionScene.cs in Exec at line 26:9
In App

ExceptionがStart側まで戻れず、try-catchができず、アプリに対して、Exceptionをthrowしてしまう。

async内でexceptionを出し、async内でtry-catch

void Start()
{
    Exec();
}
async void Exec()
{
    try
    {
        var result = await ExecUniTask();
        Debug.Log("Exec " + result);
    }
    catch (Exception e)
    {
        Debug.LogError(e.Message + ":" + e.StackTrace);
    }
}
async UniTask<float> ExecUniTask()
{
    await UniTask.Delay(1000);
    throw new Exception("例外エラー1");
    return 100f;
}

ログ

例外エラー1:  at ExceptionScene.ExecUniTask () [0x00000] in HogeProject/Assets/Scripts/ExceptionScene.cs:31 
  at Cysharp.Threading.Tasks.UniTask+ExceptionResultSource`1[T].GetResult (System.Int16 token) [0x00015] in HogeLibrary/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTask.Factory.cs:255 
  at ExceptionScene.Exec () [0x00024] in HogeProject/Assets/Scripts/ExceptionScene.cs:19

try-catchできる。