Search Unity

Android error handling in Unity3D

Discussion in 'Android' started by MajidKhosravi, Oct 16, 2017.

  1. MajidKhosravi

    MajidKhosravi

    Joined:
    Jun 21, 2013
    Posts:
    39
    Just wondering if there is a way to handle errors in the Android plugins within Unity C# script.

    Here is the scenario, sometimes initializing for example Facebook SDK causes crashes on some devices and this will crash the game, so by wrapping a try catch I was hoping to ignore this and continue the game.

    Code (csharp):
    1. try{
    2.     if (FB.IsInitialized) {
    3.          FB.ActivateApp();
    4.       }else{
    5.          FB.Init(() => {FB.ActivateApp();});
    6.        }
    7.   }catch ( System.Exception e ){
    8.     // Catch the error here and avoid the crash
    9.   }
    But it seems this approach doesn't handle such errors, any suggestions?