Re: Try Catch Else Finally

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You can get line numbers, but that is only good for showing error messages.
It's not like you can in code figure out which function call caused the
error - unless you start hard coding if statements to look for specific line
numbers - but that isn't something you would ever want to do.

cj wanted to figure out which line of code was causing the problem, to
presumably either have different error handling code, or ignore the error,
etc. That isn't something the stack trace information can realistically help
with.

Not to mention, line numbers come up only when compiled in debug mode.

"Jim Wooley" <jimNOSPAMwooley@xxxxxxxxxxx> wrote in message
news:24f81e8e3e698c817caf419aded@xxxxxxxxxxxxxxxxxxxxxxx
Your right Marina Levit has already set me straight. Only remaining
downside is I wouldn't know which line caused the exception. Thanks
for the reply.

You CAN get the line that caused the exception if you number your lines
(like old Basic). The following is perfectly acceptable VB.Net code:

10: REM This program doesn't do much
20: Try
30: REM Throw an error
40: Throw New DivideByZeroException
50: Catch ex As DivideByZeroException
60: Console.WriteLine("Error occured in line: " & Erl())
70: End Try
80: Console.ReadLine()

The output is:

Error occured in line: 40

The upside is: the line numbers are retained when you compile in release
mode. The down side is that there is a performance hit, so you would only
want to do this when it is essential you know the line causing the problem
and speed is not as important.

Jim Wooley
http://devauthority.com/blogs/jwooley/archive/2005/12/21/661.aspx




.



Relevant Pages

  • Re: Try Catch Else Finally
    ... downside is I wouldn't know which line caused the exception. ... You CAN get the line that caused the exception if you number your lines. ... REM This program doesn't do much ... 50: Catch ex As DivideByZeroException ...
    (microsoft.public.dotnet.languages.vb)
  • Re: FILESYS exception with hive registry in 4.2
    ... thanks for responding. ... debug mode. ... > It appears that urlmon is passing -1 to RegCloseKey. ... > using exception handling. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Application.ThreadException Doesnt Work Right. Why?
    ... I understand that, but what this is, is if any exception that is unintended ... we trap it along with all of the stack information etc. and send it ... >> it only functions when in debug mode. ... of any SQL Exceptions ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Object reference not set to an instance of an object.
    ... You will get more exception details if you are running the ... application in debug mode, than if you ran it in release mode. ... > Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.languages.vb)
  • IDE debugging question
    ... Sub Main ... a divide by zero exception when attempting to assign to c. ... I am now in debug mode in the IDE and can I have the ...
    (microsoft.public.dotnet.languages.vb)