in the drawing, one of my pipe network structures doesn't have a station property & caused an error when the code called for that property to be read in the first IF in the code below.
I'm not posting thousands of lines of code since the other aspects of the routine that the posted code segment is from have worked just fine until this particular situation. I know why the error is occuring & I know what to do in the drawing to make it not happen, but I'd like to be able to handle the error so that users of the routine will be informed.
so I added a TRY statement to catch that error & the error would keep occuring instead of being handled. so I though maybe TRY doesn't work on IF statements, so I added the "tempstation" variable declaration line. the error is still not getting caught.
the inner TRY / CATCH is not relevant to this discussion, I'm sure.
Then in the editor I set DEBUG > EXCEPTIONS>>> to have everything be thrown, as originally nothing was set to be thrown. That had no affect.
So can anyone tell me why this isn't working (they way I think it should)?
Try Dim tempstation As Double = oStructure.Station If oStructure.Station < StructureList(i).Station Then Try StructureList.Insert((i), (oStructure)) booApend = False GetAllStructuresFromAlignment = True Exit For Catch GetAllStructuresFromAlignment = False End Try Else booApend = True End If Catch ex As Exception msgbox("structure" & ostructure.name & " has a station ERROR") End Try
You are 'catching' an Exception, but since we can't see what your Imports include my guess is you are not Importing System so the Exception is an AutoCAD.Runtime.Exception. The Station property throws a CivilException which is caught if it is specifically referenced OR a System.Exception will also catch it. It's a good rule of thumb to determine what kind of exception is thrown under certain circumstances and catch that specific exception, then if you get thrown into another exception find what is causing that, rather than using a catch-all exception (which is essentially what catching a System.Exception would do).
Catch ex As Exception
Catch ex as Autodesk.Civil.CivilException
should fix this immediate issue.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register