By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,691 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,691 IT Pros & Developers. It's quick & easy.

About error handling in vb.net

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
Try printing out the stack trace of the exception. Maybe that will
have the data you need.

Nov 21 '05 #4

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.