System.Runtime.InteropServices.COMException
This type of exception is thrown when an unrecognised HRESULT is returned from a COM method call
You do not have to catch a COMException specifically, it will be caught by the general System.Exception.
The CLR transforms well known HRESULTS to .NET Exceptions
Check the ErrorCode property of the exception to determine the HRESULT returned by the COM object
COM Exception Catch
try
{
Globals.ThisAddIn.Application.Workbooks.Open(@"C:\temp\nofile.txt");
}
catch (System.Runtime.InteropServices.ComException ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
catch (System.Runtime.InteropServices.ComException ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext