tl:dr - How can I include a working try-catch in my Uipath custom activity?
I am trying to incorporate a Try Catch in my C# code to handle a particular exception. Here is how my code looks:
try
{
xlsBook.ExportAsFixedFormat(paramExportFormat, pDFFilePath);
}
catch (System.Runtime.InteropServices.COMException e)
{
if (e.Message.Contains("Document not saved"))
throw new System.Exception("PDF Document not saved. Check if the document is currently open");
else
throw e;
}
Now this executes perfectly when I test the code in visual studio. It catches the exception “Document not saved” and instead throws the more detailed error message I have defined.
However, when I export this package and run it on UiPath as a custom activity, it still throws the default exception rather than execute the try-catch:
Any idea how I can resolve this?
Since this is a somewhat advanced topic, tagging some awesome folks who have already built custom activities: @lakshman @balupad14 @DanielMitchell @Palaniyappan