Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

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.: