Author Topic: Trapping COM error  (Read 2761 times)

0 Members and 1 Guest are viewing this topic.

57gmc

  • Bull Frog
  • Posts: 365
Trapping COM error
« on: January 27, 2012, 05:20:36 PM »
Hi guys.

I still haven't gotten my legacy stuff converted yet, so I'm using AcadApplication.LoadDVB. However, if the vba environment didn't get installed or there was a problem loading the dvb, acad spits out "Automation Error: ****" and then my dll stops execution.  I have this in a try block thinking that a runtime exception would get thrown, but it doesn't. Do you know of any way to trap the COM error so I can recover from it?

BlackBox

  • King Gator
  • Posts: 3770
Re: Trapping COM error
« Reply #1 on: January 27, 2012, 05:40:02 PM »
Not sure if this helps:

Code - vb.net: [Select]
  1. Imports System
  2. Imports System.IO
  3. Imports System.Security.Principal
  4.  
  5. Imports Autodesk.AutoCAD.ApplicationServices
  6. Imports Autodesk.AutoCAD.DatabaseServices
  7. Imports Autodesk.AutoCAD.EditorInput
  8. Imports Autodesk.AutoCAD.Geometry
  9. Imports Autodesk.AutoCAD.Runtime
  10.  
  11. Namespace Foo
  12.  
  13.     Public Class FooCommands
  14.  
  15.         <CommandMethod("FINDVBA")> _
  16.         Public Sub FINDVBA()
  17.             Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  18.             Dim ed As Editor = acDoc.Editor
  19.             Dim oDb As Database = acDoc.Database
  20.             Dim filePath As String
  21.             Try
  22.                 filePath = HostApplicationServices.Current.FindFile("AcVBA.arx", oDb, FindFileHint.Default)
  23.                 If filePath <> Nothing Then
  24.                     ed.WriteMessage(vbLf & filePath & vbLf)
  25.                 Else
  26.                     ed.WriteMessage(vbLf & "** AcVBA.arx not found ** " & vbLf)
  27.                 End If
  28.             Catch ex As Exception
  29.                 ed.WriteMessage(vbLf & "** An exception has occurred ** " & vbLf)
  30.             End Try
  31.         End Sub
  32.  
  33.     End Class
  34.  
  35. End Namespace
  36.  
« Last Edit: January 27, 2012, 06:23:55 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

57gmc

  • Bull Frog
  • Posts: 365
Re: Trapping COM error
« Reply #2 on: January 27, 2012, 05:55:49 PM »
Thanks. Originally, I had System.Exception in my catch statement, but I switched it for Autodesk.AutoCAD.Runtime.Exception. Shoulda kept it the way it was.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trapping COM error
« Reply #3 on: January 27, 2012, 06:30:11 PM »

I'm pretty sure that

Code - vb.net: [Select]
  1. Catch ex As Exception

will throw an error ... something like Ambigious Reference
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

BlackBox

  • King Gator
  • Posts: 3770
Re: Trapping COM error
« Reply #4 on: January 27, 2012, 07:23:05 PM »
Maybe it was the project I was in; there was no listed error, but admittedly I did not debug.

When I read Ed's reply, I recall having to change Exception as he stated above to mitigate the ambiguous error in previous projects.

Ironically, I actually posted that code for the FindFile usage, and not the Try Catch structure. LoL.
« Last Edit: January 27, 2012, 10:26:59 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."