What’s wrong with this code? Why doesn’t it catch the exception thrown by SelectNewPrintDriver if the PDF995 is not installed?
try
{
pm.SelectNewPrintDriver(“PDF995”);
}
catch (InvalidOperationException)
{
TaskDialog.Show(“Error”, “Cannot find printer PDF995”);
return;
}
Because SelectNewPrintDriver throws Autodesk.Revit.Exceptions.InvalidOperationException, not System.InvalidOperationException. So I’d suggest that you include:
using Autodesk.Revit.Exceptions;
in your files so that the compiler will give this error and remind you to resolve the ambiguity about which exception you are trying to catch.
‘InvalidOperationException’ is an ambiguous reference between ‘System.InvalidOperationException’ and ‘Autodesk.Revit.Exceptions.InvalidOperationException’