Search Unity

Visual Studio not catching AssertionException

Discussion in 'Code Editors & IDEs' started by sitnduck, Sep 27, 2021.

  1. sitnduck

    sitnduck

    Joined:
    Jun 29, 2016
    Posts:
    15
    Hi! I'm probably missing something trivial here, but I can't seem to get Visual Studio to break on AssertionException raised by assertions.

    I can break on other exceptions (invalid arguments etc.), and I can see the exception being raised (so that is set up correctly), it's just not breaking in the debugger.

    I tried adding custom exceptions to Visual Studio (e.g. UnityEngine.Assertions) but that didn't change anything.

    It would be great to be able to break as assertions happen, to get access to the state of variables etc. Note that I DON'T want to enable ALL exceptions for breaking as it looks like many 3rd party modules are causing benign exceptions.
     
  2. sitnduck

    sitnduck

    Joined:
    Jun 29, 2016
    Posts:
    15
    In case anyone wonders, I found the answer:

    If you want Visual Studio to BREAK (through an exception) on a Unity assertion (e.g. Assert.Istrue(...)), you must add the following exception to your "Common Language Runtime Exceptions" setting (Debug-> Exception Settings):

    UnityEngine.Assertions.AssertionException

    e.g.: