About error handling in vb.net

  • Thread starter Thread starter Tom
  • Start date Start date
T

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
 
Tom said:
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().Name'.
 
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 ?
 
Try printing out the stack trace of the exception. Maybe that will
have the data you need.
 
Tom said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top