.NET

Reply
New Member
ssomick
Posts: 2
Registered: ‎11-30-2012
Message 1 of 2 (148 Views)

try catch isn't catching the error

148 Views, 1 Replies
12-28-2012 07:27 AM

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

 

*Expert Elite*
Jeff_M
Posts: 4,293
Registered: ‎07-22-2003
Message 2 of 2 (127 Views)

Re: try catch isn't catching the error

12-28-2012 02:48 PM in reply to: ssomick

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).

 

So changing

Catch ex As Exception

 

to 

Catch ex as Autodesk.Civil.CivilException

 

should fix this immediate issue.

Jeff_M, also a frequent Swamper
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.