How to properly catch Unity Assertion failures?

I have a custom mesh generation function. Depending on the data passed to this function, it might generate an Assertion Failure, which is displayed in the unity console:

Assertion failed: Converting invalid
MinMaxAABB
UnityEngine.Mesh:set_vertices(Vector3)

The line that generate the assertion failure is:

renderedMesh.vertices = tempvertices;

Now obviously, this means there is a problem with the tempvertices provided to the mesh. I’m NOT looking for an answer on what conditions might generate such an assertion failure.
My question is how do I catch it? (So I can display my OWN message in the unity console.)

I have tried putting it in a try-catch block, just after setting the [UnityEngine.Assertions.Assert.raiseExceptions][1] flag (which appears to exist expressly for this purpose) to true, like so, but it had no effect on the output:

        UnityEngine.Assertions.Assert.raiseExceptions = true;
        try
        {
            renderedMesh.vertices = tempvertices;
        }
        catch (UnityEngine.Assertions.AssertionException e)
        {
            Debug.Log("Problem generating mesh for custom object: " + name + " . Aborting mesh generation.");
            renderedMesh.name = "Problem generating mesh";
            return;
        }

First of all assertions are not exceptions. They are similar but serve a different purpose. An assertion should never ever show up. If it does it’s usually an indication that there is something wrong in the code.

Second this assertion seems to be a C++ assert inside the native code of Unity. “UnityEngine.Assertions.Assert” is a quite new class and only belongs to managed code. Also unlike the “normal” C++ assert the managed Assert class is only ment for logging those problems. Unity’s Assertions usually are not included in a build. Assets are purely ment for debugging and not for control flow at runtime. Even exceptions aren’t ment for that.

If the mesh data is user provided your best solution is to manually do some sanity checks on the vertex data before you pass it to your mesh.

Common problems i could think of would be too large float values (large in the sence of magnitude so +-) or “NaN” values.