Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Try / Catch in coroutines causes an internal compiler error

Discussion in 'Scripting' started by L-W, Oct 30, 2015.

  1. L-W

    L-W

    Joined:
    Mar 3, 2013
    Posts:
    20
    Hey everyone,

    I'm experiencing an internal compiler error when including any try/catch in a coroutine, it seems to reproduce no matter what the case.
    I managed to reproduce it by simply creating a new, completely blank unity project (using Unity 5.2.2f1, and VS2010), adding a script to the main camera and adding this method to the class:

    Code (csharp):
    1.  
    2. public System.Collections.IEnumerator TestCoroutine() {
    3.     try{}
    4.     catch (System.Exception e){}
    5.     yield break;
    6. }
    7.  
    This causes the console to be flooded with text, but the two important lines (I think) are these:

    Code (csharp):
    1.  
    2. Unhandled Exception: System.ArgumentException: Trying to emit a local from a different ILGenerator.
    3.  
    4. Internal compiler error at Assets/dawdwd.cs(11,43):: exception caught while emitting MethodBuilder [<TestCoroutine>c__Iterator0::MoveNext]
    5.  
    I've searched both google and these forums and while it seems that others are experiencing the same issue, I've found no solution. I apologize if the answer is actually out there and I couldn't find it, but what I'm mainly wanting to know is: Is this a widespread issue or is it only me and a few others that are experiencing this problem?

    Any help is greatly appreciated!
     
  2. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    Hey. This page could be helpful.
     
    L-W likes this.
  3. L-W

    L-W

    Joined:
    Mar 3, 2013
    Posts:
    20
    Duugu, that page you linked actually really helped me. By some miracle of god Tim Tregubov's TTMonoBehaviour script manages to compile without an internal compiler error which means I can reverse engineer it to suit what I need! Thanks man, muchly appreciated.
     
  4. LightningIsAwesome

    LightningIsAwesome

    Joined:
    Nov 14, 2016
    Posts:
    3
    Not actually try{} catch(Exception) but catch{Exception e}, trying to access exception in coroutine cause internal compiler error
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    This is the kind of bug that will get an immediate response if you file a bug report! If you just post on the forums about these things, the bug will still be around one year later!