473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Finding current Procedure

Finding current Procedure

I want to write errors to a log-file, where the error log contain the
description of where the error occurred and what kind of error it was.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

On Error GoTo errHandler

'Some code

If Somthing Then

"do this"

Else

"do that"

End If

Exit Sub

errHandler:

myPrintToFileProcedure("Error:" & Err.Number & " - " & Err.Description & "
in procedure Button1_Click")

End Sub

Is it possible to get the text Button1_Click dynamically from the procedure
that raise the error, so that this don't need to be hardcoded?

TIRislaa

Nov 20 '05 #1
6 1246
* "Tor Inge Rislaa" <to*************@rislaa.no> scripsit:
I want to write errors to a log-file, where the error log contain the
description of where the error occurred and what kind of error it was.


\\\
MsgBox(System.Reflection.MethodBase.GetCurrentMeth od().Name)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Tor,
I would use a Try/Catch and use the Exception.ToString method to get the
FULL stack trace along with the message description & other information that
the Exception itself may be offering:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
'Some code
If Somthing Then
"do this"
Else
"do that"
End If
Catch ex As Exception
myPrintToFileProcedure(ex.ToSTring())
End Try
End Sub

However!!! I would not include the above code in each event handler. I would
include it once in the Application.ThreadException event.

Something like: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Some code
If Somthing Then
"do this"
Else
"do that"
End If
End Sub
Public Shared Sub Main()
AddHandler Application.ThreadException, AddressOf OnThreadException
Application.Run(New MainForm)
End Sub

Private Sub OnThreadException(sender As Object, _
ByVal e As System.Threading.ThreadExceptionEventArgs)
Try

myPrintToFileProcedure(ex.ToSTring())
Catch ex As Exception
' Don't want to end the app here! ;-)
End Try
End Sub

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

Hope this helps
Jay
"Tor Inge Rislaa" <to*************@rislaa.no> wrote in message
news:IT******************@news4.e.nsc.no... Finding current Procedure

I want to write errors to a log-file, where the error log contain the
description of where the error occurred and what kind of error it was.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

On Error GoTo errHandler

'Some code

If Somthing Then

"do this"

Else

"do that"

End If

Exit Sub

errHandler:

myPrintToFileProcedure("Error:" & Err.Number & " - " & Err.Description & "
in procedure Button1_Click")

End Sub

Is it possible to get the text Button1_Click dynamically from the procedure that raise the error, so that this don't need to be hardcoded?

TIRislaa

Nov 20 '05 #3
Thanks!
Is it also possible to get a line number in current procedure

TIRislaa

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> skrev i melding
news:eu**************@tk2msftngp13.phx.gbl...
* "Tor Inge Rislaa" <to*************@rislaa.no> scripsit:
I want to write errors to a log-file, where the error log contain the
description of where the error occurred and what kind of error it was.


\\\
MsgBox(System.Reflection.MethodBase.GetCurrentMeth od().Name)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
* "Tor Inge Rislaa" <to*************@rislaa.no> scripsit:
Is it also possible to get a line number in current procedure


<http://groups.google.de/groups?selm=u7POIgjfDHA.3616%40TK2MSFTNGP11.phx.gb l>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Ot
In reading that I notice that it "should not be deployed to end-users."

If my program as distributed generates an error log that I want the
end-user to send to me, I would I want the line number, right?

There must be a good reason for you to give that advice, but other than
sparing the size of the .pdb file on the end-user machine I can't see it.
Can you explain the reason further?

Regards,
Ot

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
* "Tor Inge Rislaa" <to*************@rislaa.no> scripsit:
Is it also possible to get a line number in current procedure

<http://groups.google.de/groups?selm=...FTNGP11.phx.gb
l>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #6
* "Ot" <ur***@tds.invalid (use net)> scripsit:
In reading that I notice that it "should not be deployed to end-users."

If my program as distributed generates an error log that I want the
end-user to send to me, I would I want the line number, right?

There must be a good reason for you to give that advice, but other than
sparing the size of the .pdb file on the end-user machine I can't see it.
Can you explain the reason further?


Maybe performance will be not as good as in the release version and
recreation of the source code will be easier with the debug information.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Twan Kennis | last post by:
Hi, I have a DB2 database on the IBM iSeries platform, on which I created several Stored Procedures with the SQLCODE as a return-parameter. These Stored Procedures are called from a Windows...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
5
by: Lyn | last post by:
Is there any way of determining in VBA the name and arguments of the currently executed procedure? To assist in debugging, I would like to be able to trace the procedures as they are executed. ...
2
by: VMI | last post by:
Hi, I have a Windows datagrid that's attached to a filled datatable. The grid also has a tablestyle. Since the data from the grid comes from a datatatable, how can I retrieve the data from a...
16
by: Brian Tkatch | last post by:
I have a PROCEDURE that test other PROCEDUREs. Timings_Call ------------------ Id Group Name Text Timings_Log
2
by: ARK | last post by:
Database: DB2 AIX V8.* Question: I want to be able to get the 'Client login ID' aka 'Execution ID' (as opposed to the authid or application_id) for the current connection within a stored...
3
by: birju | last post by:
Hi, I'm running SQL Profiler on an SQL Server 2000 database. I see that one stored procedure gets repeatedly executed having a handle of '1'. This query takes a long time to complete. How do I...
7
by: DarthBob88 | last post by:
I have to go through a file and replace any occurrences of a given string with the desired string, like replacing "bug" with "feature". This is made more complicated by the fact that I have to do...
1
by: Glenton | last post by:
Hi All Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm: #!/usr/bin/env python #This is meant to solve a maze with Dijkstra's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.