Re: Try Catch Else Finally
- From: "Marina Levit [MVP]" <someone@xxxxxxxxxx>
- Date: Fri, 17 Mar 2006 12:41:12 -0500
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
.
- Follow-Ups:
- Re: Try Catch Else Finally
- From: Jim Wooley
- Re: Try Catch Else Finally
- References:
- Re: Try Catch Else Finally
- From: cj
- Re: Try Catch Else Finally
- From: Jim Wooley
- Re: Try Catch Else Finally
- Prev by Date: Get All Virtual Directory(path) in IIS
- Next by Date: Q: Closing a form
- Previous by thread: Re: Try Catch Else Finally
- Next by thread: Re: Try Catch Else Finally
- Index(es):
Relevant Pages
|