Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception class in VFP and VB 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
566
0
16
US
Colleagues,
In VFP, when I used Try-Catch-End Try construct, I always "caught" an error into Exception object. That Exception class in VFP has two properties which I used every time: LineNo and LineContents.
LineNo - the number of the line in the code that erred;
LineContents - the command/code on that line that erred.
Now, looking at the description of the Exception class in .NET, I do not see anything similar to these two properties.
Where/how can I obtain the info about erred code and line number?
AHWBGA!


Regards,

Ilya
 
Have a look at the StackTrace property of the exception object - but be aware you cannot get full info from a published program, only when running in debug mode
 
Thank you, StrongM!
This indeed got me line # and erred proc's name.
"be aware you cannot get full info from a published program, only when running in debug mode" - Not sure I follow: page does not specify that this property's not available for EXE on run time...

Regards,

Ilya
 
From the full StackTrace class documentation (worth pointing out that Exception.StackTrace is not a StackTrace object, it is just a string representation of one - so Microsoft don't provide the full StackTrace documentation under Exception)

StackTrace information will be most informative with Debug build configurations. By default, Debug builds include debug symbols, while Release builds do not. The debug symbols contain most of the file, method name, line number, and column information used in constructing StackFrame and StackTrace objects.

For example here's the output from a debug and a Release build of my test rig app that deliberately raised a trappable error ...

Code:
[blue]    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim a(5) As String
        Try
            a(6) = "spoon"
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try
    End Sub[/blue]

Debug:
debugdlg_iil5rf.png



Release:
releasedlg_uanoip.png



 
 https://files.engineering.com/getfile.aspx?folder=fc7ee480-597f-46d0-8742-8f4021df9ae8&file=debugdlg.png
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top