.NET

Reply
Distinguished Contributor
SRSDS
Posts: 243
Registered: ‎04-15-2011
Message 1 of 6 (166 Views)

Error Trapping

166 Views, 5 Replies
03-14-2012 01:16 PM

In VB6 I used to use

On Error GoTo My_Error
'Code
   On Error GoTo 0
   Exit Sub
My_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") on line " & Erl & " in procedure MyProcedure of Module MyModule"

 

By using this in VB.net it the error is skipped and it jumps to the error routine. Easily added using MZ tools.

The same code doesn't report what line but at least reports an error.

 

 Using the Try, Catch & Finally method often just crates a fatal error and I have to step through code trying to work out what the problem is.

 

A big problem is that I have spent a long time creating an application with several reactors. I'm not sure if I will ever figure out why it is creating fatal errors.

 

Is there some reading material that can help me trap errors or work out if I have not disposed of something that should have been?

 

Mentor
MarkPendergraft
Posts: 375
Registered: ‎06-27-2005
Message 2 of 6 (161 Views)

Re: Error Trapping

03-14-2012 01:40 PM in reply to: SRSDS

I've had some fatal errors from using Try/Catch ex as Exception/End Try as well.  However I was able to trap them using the following:
Try

'code.....

Catch

'error message

End Try.

 

It obviously doesn't provide you with an exception that you can then report to your user, but you should be able to figure out what the error is while debugging and then tell your code to catch it.

 

-Mark

Valued Mentor
gasty1001
Posts: 444
Registered: ‎04-11-2010
Message 3 of 6 (156 Views)

Re: Error Trapping

03-14-2012 01:49 PM in reply to: SRSDS

Hi, 

 

This link may help you to understand exceptions: http://msdn.microsoft.com/en-us/library/5b2yeyab(v=vs.100).aspx

 

Gaston Nunez

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (153 Views)

Re: Error Trapping

03-14-2012 01:52 PM in reply to: SRSDS

Try in the Visual studio to go to Project --> Properties-->Compile Tab

and set Option Strict to On, then hit F5, you will be see many possible

bad lines in your code before you run it, then revert back Option Stict to Off

and run again

Maybe it will be usefull for you

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Distinguished Contributor
SRSDS
Posts: 243
Registered: ‎04-15-2011
Message 5 of 6 (119 Views)

Re: Error Trapping

03-15-2012 09:00 AM in reply to: Hallex

It most often never makes it to the catch part . The fatal error is initiated on the bad bit of code.

Something I will have to accept it seems.

 

That option strict generates a mass of errors. I'll see if I can spot anything unusual there.

Thanks all.

Valued Contributor
Paulio
Posts: 82
Registered: ‎06-26-2008
Message 6 of 6 (111 Views)

Re: Error Trapping

03-15-2012 09:59 AM in reply to: SRSDS

If you're importing Autodesk.AutoCAD.Runtime and you do a "Catch ex as exception" you're only catching the Autodesk.AutoCAD.Runtime exceptions so if you get a System.Exception it will error and not hit the catch.

 

The Runtime.exception inherits System.exception so catching System.exceptions should get them all.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community