title: What's a good global exception handling strategy for Unity3D?
body: <p>I'm looking into doing some Unity3D scripting stuff, and I'd like to set up global exception handling system. This is not for running in the release version of the game, the intention is to catch exceptions in user scripts and also in editor scripts and make sure they are forwarded to a database for analysis (and also to send email to relevant devs so they can fix their shizzle). </p>
  
  <p>In a vanilla C# app I'd have a try-catch around the Main method. In WPF I'd hook one or more of the <a href="https://stackoverflow.com/questions/1472498/wpf-global-exception-handler">unhandled exception events</a>. In Unity...?</p>
  
  <p>So far the best I've been able to come up with is something like this:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public abstract class BehaviourBase : MonoBehaviour {
  
      // Use this for initialization
      void Start () {
  
      }
  
      // Update is called once per frame
      void Update () {
          try
          {
              performUpdate();
              print("hello");
          }
          catch (System.Exception e)
          {
              print(e.ToString());
          }
  
      }
  
      public abstract void performUpdate();
  
  }
  </code></pre>
  
  <p>In other scripts, I derive BehaviourBase instead of MonoBehavior and implement performUpdate() instead of Update(). I haven't implemented a parallel version for Editor clases but I assume I'd have to do the same thing there. </p>
  
  <p>I don't like this strategy, however, because I'll have to backport it to any scripts we grab from the community (and I'll have to enforce it on the team). The Editor scripts don't have a single point of entry comparable to MonoBehavior either, so I assume I'd have to implement exception safe versions of wizards, editors and so on. </p>
  
  <p>I've seen suggestions about catching log messages (as opposed to exceptions) using  <a href="http://docs.unity3d.com/Documentation/ScriptReference/Application.RegisterLogCallback.html" rel="noreferrer">Application.RegisterLogCallback</a>, but this makes me uncomfortable because I'd need to parse the debug log string rather than having access to the actual exceptions and stacktraces.</p>
  
  <p>So... what's the right thing to do?</p>