Search Unity

Try - Catch blocks troubles (SOLVED)

Discussion in 'iOS and tvOS' started by Brian-Kehrer, Sep 13, 2009.

  1. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    I'm having a bit of difficulty properly utilizing the try catch blocks on the iPhone.

    As I understand, the code below should not throw an exception, and doesn't in the editor, or in system builds -> properly printing the message. But in the iPhone, I'm getting unhanded exceptions (DivideByZero used here as a simple example) ... Am I missing something really basic here?

    The iPhone console looks like this:

    -> applicationDidBecomeActive()
    DivideByZeroException: Division by zero
    tester.Start ()

    Snow Leopard + iPhone Advanced
    Code (csharp):
    1.  
    2. void Start () {
    3.        
    4.         try{
    5.             throw new System.DivideByZeroException();  
    6.         }
    7.         catch{
    8.             Debug.Log("exception caught" + Time.time); 
    9.         }
    10.    
    11.     }
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It should...it will do nothing but throw an exception, including in the editor. Also, are you using "Fast but no exceptions"? Because that means no exceptions, including try/catch.

    --Eric
     
  3. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Hello,
    please submit bug report with sample project attached to it.
     
  4. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    Well, yes. Exactly. The exception should be handled is what I meant.

    I turned off "Fast but no exceptions", for exactly that reason.

    I'll submit a bug report.
     
  5. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    Any build stripping beyond 'Strip Assemblies' is removing the Try-Catch exception handling. (i.e. Strip Byte Code and Use Micro mscorlib). Maybe this was obvious to everyone else. I'm just a bit slow I guess. :?

    Also, it seems try - catch works even with 'No Exceptions' selected instead of 'Slow and Safe', which is a bit unexpected, but a pleasant surprise perhaps for those who assumed otherwise.

    If this is still a bug, I'll submit the files.
     
  6. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Brian,
    please submit bug report.
    Thanks!
     
  7. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    Have found out the same (stripping breaks try catch) - this is quite essential to know - because it could lead to deadlock situations if an app relies on try-catch for error handling.

    And as Brian posted already try-catch still works if "Fast but no exceptions" is enabled. I have nothing against this, provided the code still uses the optimized codepaths...