How do I stop/pause/break a build automatically on error?

I’m making a web player game, and I need some kind of way to break or pause when an error occurs.

Right now the game continues even if it hits an error, and that error breaks the collision code of an object, which breaks the gameplay entirely. The issue is that this error happens seemingly randomly, and I don’t know the cause, so I can’t break manually.

Is there a way I can make the game break/exit/pause/stop executing when an error occurs?
And maybe even show the error as well, if possible.

Thanks!

Acegikmo, I just found that in MonoDevelop you can set which exceptions you want to break on automatically by using the Run->Exceptions menu. Then select the exceptions you want to break on. Most useful is the null error exception for me.

I know this question is years old, but for Visual Studio users, this functionality has been implemented in version 2.0 Preview 2 (1.9.9) of Visual Studio Tools for Unity.

Just enable the “Exception support (experimental)” in Options->Tools for Unity->General, and use “Attach to Unity and Play”.

Unity will automatically break when an exception is thrown and Visual Studio displays all sorts of debugging information.

This answer has the complete guide. @Ziplock9000 is correct, it only works when you:

  • Enable the “Exception support” in Options => Tools for Unity
  • Turn on “Common Language Runtime Exceptions” in the DEBUG => Windows => Exception Settings dialog in Visual Studio.
  • Use “Attach to Unity and Play”