Search code examples
c#revit-apirevit

How do I catch Revit errors in Revit API?


I'm trying to catch an error displayed in Revit to perform some handle operations. Error is due to the connection of points as shown in the image below. Error image This is what I have tested with so far.

try
{
    var pipe = Pipe.Create(doc, firstPipeType.Id, level.Id, startCon, 
    pathXyz[0]);
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException e)
{
    message = e.Message;
    return Result. Failed;
}

Based on the documentation, I am trying to catch and handle the following exception. "Autodesk.Revit.Exceptions.InvalidOperationException: Thrown when the new pipe fails to connect with the connector."


Solution

  • The error message is different from the exception. The instructions on how to handle the error message are provided by The Building Coder in the topic group on Detecting and Handling Dialogues and Failures.