473,398 Members | 2,212 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,398 software developers and data experts.

About error handling in vb.net

Tom
Hi All :

I have some question about error handling :

Can I get some system varabile which can get current function name , also if
error occur, can I get some system varabile which show the error line
number ?

For example :

Function myFunction() as integer
5 try
6 a = sys.opening
7 catch (ex as excpeption)
8 debug.writeline system.functionname ' return a string type and
value is "myFunction"
9 debug.writeline system.errorline ' return a integer type and value
is "6"
10 end catch
End Function
Thanks
Nov 21 '05 #1
4 6801
"Tom" <pc***@tomgroup.com> schrieb:
Can I get some system varabile which can get current function name , also
if
error occur, can I get some system varabile which show the error line
number ?


Line numbers: If you used line numbers, you can determine the line number
using 'Err.Erl'.

Method name: 'System.Reflection.MethodBase.GetCurrentMethod().N ame'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Tom
But it seem apply for private function
it return Run-time exception thrown : System.ArgumentException - Cannot
evaluate a security function
also Err.erl is 0.

Also can I also get current class / current module name ?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> ???
news:uS**************@tk2msftngp13.phx.gbl ???...
"Tom" <pc***@tomgroup.com> schrieb:
Can I get some system varabile which can get current function name , also if
error occur, can I get some system varabile which show the error line
number ?


Line numbers: If you used line numbers, you can determine the line number
using 'Err.Erl'.

Method name: 'System.Reflection.MethodBase.GetCurrentMethod().N ame'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Try printing out the stack trace of the exception. Maybe that will
have the data you need.

Nov 21 '05 #4
"Tom" <pc***@tomgroup.com> wrote in message
news:ug**************@TK2MSFTNGP09.phx.gbl...
Can I get some system varabile which can get current function
name? also if error occur, can I get some system varabile
which show the error line number ?


Yes.

For function name (outside of an Exception Handler), use
[System.Reflection.MethodBase].GetCurrentMethod.Name()

For Line numbers in an Exception Handler, examine the Stack
Trace of the Exception you caught, but /only/ if your program
(or whatever) was built in Debug Mode. When you rebuild in
Release Mode, the line numbers no longer appear.

Function myFunction() as integer
Dim a As ...
Try
a = sys.opening
Catch (ex as Exception)
MessageBox.Show( ex.ToString() )
End Catch
End Function

HTH,
Phill W.
Nov 21 '05 #5

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

Similar topics

9
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in...
5
by: Lau Lei Cheong | last post by:
Hello, I'm currently using Application_Error method in Global.asax.cs to handle errors. Recently, I heard about Page.ErrorPage and plan to use it for handling errors on certain pages. Are...
38
by: Arjang | last post by:
http://www.codeproject.com/useritems/CSharpVersusVB.asp
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
21
by: bruno_guedesav | last post by:
I've made a function to fetch all results as an array of result- arrays. Getting the result arrays is easy, via mysql_fetch_array, and function itself is quite simple, as follows: function...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
9
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.