Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Dave Lock · Mar 24, 2013 at 02:09 PM · c#iosexceptiontry-catch

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

Trying to build an app to iOS, & to my surprise it seems code in a standard C# try-catch block hangs the build. Does try-catch work in an iOS build? I hope I can post code here properly (first time), but the offending code is:

 try {
             xmlDoc.LoadXml(xmlDocString);
             try {
                 steering = float.Parse(xmlDoc.DocumentElement.Attributes["steering"].Value);
             } catch {
                 steering = 0f;
             }
 } catch {
 }


It hangs on the inner try catch block. I nested the try-catch blocks to isolate the problem. xmlDoc is an XmlDocument object that loads an XML string sent via a SendMessage (so the string is cast from type object). I understand an exception may occur because the XML string may not contain the attribute. But isn't try-catch supposed to handle this kind of exception handling? Does Android build have the same issue?

Any info welcome & appreciated. Thanks.

Comment
Add comment · Show 3
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
avatar image CrystalRain0329 · Aug 09, 2013 at 10:40 PM 0
Share

Just curious, did you ever get this to work? I'm on iOS too, getting the same error with

 try
 {
       System.Convert.FromBase64CharArray(charArray, 0, charArray.Length);
 }
 catch //Also tried catch (System.FormatException) since that's the error it's throwing but no luck
 {
 }
avatar image ArkaneX · Aug 10, 2013 at 09:43 AM 0
Share

Unfortunately I can't test on iOS, and I know the clue of the problem is try catch, but as a side note, you can convert the inner one to:

 float steering = 0f;
 var attrSteering = xmlDoc.DocumentElement.Attributes["steering"];
     
 if(attrSteering == null || !Single.TryParse(attrSteering.Value, out steering))
 {
     steering = 0f;
 }
avatar image boddole · May 21, 2014 at 01:05 AM 0
Share

I've also had this problem on iOS, and removing the try catch block fixed the error (and I did have Slow and Safe selected).

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JuhaRMD · Jan 21, 2014 at 01:26 PM

Do you have exception handling enabled? If you want to catch exceptions on iOS you should make sure that the exception handling has been enabled (from Project Settings -> Player Settings -> iOS -> Other Settings set "Script Call Optimization" to "Slow and Safe").

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
avatar image
0

Answer by Slobdell · Aug 10, 2013 at 04:44 PM

It should work. But you can't really figure out the problem if you don't know what it is. Change your catch methods to this

 catch(Exception e){
      Debug.log(e.toString());
 }

That will help you isolate the problem, it's probably something really simple but you won't know unto you see what the errors are

Comment
Add comment · Show 1 · 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
avatar image Slobdell · Aug 10, 2013 at 04:45 PM 0
Share

Error will print in xcode not unity fyi

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

15 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

Related Questions

Multiple Cars not working 1 Answer

Audio: how do I immediately play a new audioclip without delay(code included)? 2 Answers

C++ windows DLL and Android? 1 Answer

Things to do to port game made for iOS in Unity to Android? 2 Answers

A node in a childnode? 1 Answer


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