Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mike29willems · Sep 28, 2019 at 07:02 PM · exceptiontry-catch

Why is the try catch method in Unity not preventing my app from quitting/crashing?

I have two methods SaveToiCloud and GetFromiCloud that are doing what they say. I removed on purpose any null checks to see if the try and catch could do their job alone. However in Unity it is not crashing but when I build it to swift it is. "terminating with uncaught exception of type NSException (lldb) " . I thought I'am catching every exception... Also the crash ONLY happens when I first try to get the value (this is not giving me an error!) and then try to save it (this is). I think this is because I'am setting the value to null with GetFromiCloud, but then again I thought the exception should be catched.

 public void SaveToiCloud()
     {
         try{
         // all variables are stored on GlobalD. with default value assigned to them
        // all variables in this class are stored with no default value (to check)

             level = GlobalData.instance.level;
             health = GlobalData.instance.health;
             doorOpen = GlobalData.instance.doorOpen;
             nameplayer = GlobalData.instance.nameplayer;
 
             IntToDictionary(); //I have made sure no keys are overriding
             StringToDictionary();
             BoolToDictionary();
 
             iCloudSaveValue();
         }
 
         catch (System.Exception ex)
         {//Unity is successfully showing me this exception without crashing/quitting
             Debug.Log(ex);
             Debug.Log(ex.Message);
             Debug.Log(ex.StackTrace);
             
         }
     }
 
     public void GetFromiCloud()
     {
         try
         {
             GetIntFromiCloudDic();
             GetStringFromiCloudDic();
             GetBoolFromiCloudDic();
 
             GlobalData.instance.level = level;
             GlobalData.instance.health = health;
             GlobalData.instance.doorOpen = doorOpen;
             GlobalData.instance.namePlayer = namePlayer;
 
             SaveSystem4.SavingToFile();
 
         }
 
         catch (System.Exception ex)
         {
             Debug.Log(ex);
             Debug.Log(ex.Message);
             Debug.Log(ex.StackTrace);
         }
 public void iCloudSaveValue()
     {
         foreach (KeyValuePair<string, int> pair in DicInt)
         {
             bool success = iOSPlugin.iCloudSaveIntValue(pair.Key, pair.Value);
             if (success)
             {
                 iOSPlugin.ShowAlert("iCloud Value Saved Success", pair.Value.ToString());
             }
             else
             {
                 iOSPlugin.ShowAlert("iCloud Value Saved failed", pair.Value.ToString());
             }
         }
 void GetIntFromiCloudDic()
     {
         try
         {
             level = iOSPlugin.iCloudGetIntValue("Level"); // I know I should use null check
             health = iOSPlugin.iCloudGetIntValue("Health");
         }
         catch
         {
             iOSPlugin.ShowAlert("iCloud Value", string.IsNullOrEmpty(nameplayer) ? "Nothing Saved Yet..." : level.ToString());
             iOSPlugin.ShowAlert("iCloud Value", string.IsNullOrEmpty(nameplayer) ? "Nothing Saved Yet..." : health.ToString());
         }
       
         
     }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Pangamini · Sep 28, 2019 at 09:09 PM

Your c# code cannot catch exceptions produced eg. by c++ runtime, as the two are not the same thing. You have to catch it on the native code side, and optionally pass it to the Unity as a value, though I haven't studied this problem much and there might be a better way.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stop Game on Exception 4 Answers

C# try catch block doesn't work for iOS? 2 Answers

Try/Catch block stops exception from happening 0 Answers

How do I catch the SendMessage Has No Reciever exception thrown when I try to run a function with SendMessage that does not exist? 1 Answer

Try Catch not working with VideoPlayer 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges