Home All Groups Group Topic Archive Search About

current function / sub name ?

Author
26 May 2006 7:52 PM
Brahm
Hey Guys!

    is there anyway to get in runtime current function or sub name ?

Daniel

Author
26 May 2006 8:20 PM
Brahm
ok

the answer is: msgbox(System.Reflection.MethodBase.GetCurrentMethod.Name)

"Brahm" <daniel.br***@contronic.com.br> escreveu na mensagem
news:O9gn43PgGHA.4708@TK2MSFTNGP04.phx.gbl...
Hey Guys!

    is there anyway to get in runtime current function or sub name ?

Daniel
Author
27 May 2006 7:31 AM
Cor Ligthert [MVP]
Brahm,

You found your answer, but I am always curious why somebody needs this kind
of information, while he is in fact in the sub?

Cor

Show quoteHide quote
"Brahm" <daniel.br***@contronic.com.br> schreef in bericht
news:O9gn43PgGHA.4708@TK2MSFTNGP04.phx.gbl...
> Hey Guys!
>
>    is there anyway to get in runtime current function or sub name ?
>
> Daniel
>
>
Author
27 May 2006 12:08 PM
+Vice
We, for one, use this for code reusability, whereby all functions/subs that
can throw an error will call a global error message handler that logs the
message for troubleshooting when things goes wrong.  Can't always rely on
the user to give us the details of the error.  With this we know where and
when the error occurred.

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23VMQe9VgGHA.3984@TK2MSFTNGP02.phx.gbl...
> Brahm,
>
> You found your answer, but I am always curious why somebody needs this
> kind of information, while he is in fact in the sub?
>
> Cor
>
> "Brahm" <daniel.br***@contronic.com.br> schreef in bericht
> news:O9gn43PgGHA.4708@TK2MSFTNGP04.phx.gbl...
>> Hey Guys!
>>
>>    is there anyway to get in runtime current function or sub name ?
>>
>> Daniel
>>
>>
>
>
Author
27 May 2006 12:18 PM
Cor Ligthert [MVP]
> We, for one, use this for code reusability, whereby all functions/subs
> that can throw an error will call a global error message handler that logs
> the message for troubleshooting when things goes wrong.  Can't always rely
> on the user to give us the details of the error.  With this we know where
> and when the error occurred.
>
But you are in the methode, why do you than need it to get it in that
difficult making only your program larger way?

Call("MyMethode") seems for me easier than
Call(System.Reflection.MethodBase.GetCurrentMethod.Name)

Therefore I still don't understand it?

Cor
Author
29 May 2006 1:53 AM
+Vice
Are you saying that since you're already in the method then to call the
global error handler and pass it the method/function name?  If so, it's too
much of a hassle when you have so many subs/functions to work with.  Like I
said, we want reusability.  For example, copy Call("MyHandler") everywhere I
need a global error handler.  However, I think I should bank on the call
stack for the global handler now.  We do use a global Unhandled Exception
handler to capture any errors and it'll be nice to use the call stack to get
the sub/function name instead as suggested by Martin.

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:eCHQwdYgGHA.3900@TK2MSFTNGP05.phx.gbl...
>> We, for one, use this for code reusability, whereby all functions/subs
>> that can throw an error will call a global error message handler that
>> logs the message for troubleshooting when things goes wrong.  Can't
>> always rely on the user to give us the details of the error.  With this
>> we know where and when the error occurred.
>>
> But you are in the methode, why do you than need it to get it in that
> difficult making only your program larger way?
>
> Call("MyMethode") seems for me easier than
> Call(System.Reflection.MethodBase.GetCurrentMethod.Name)
>
> Therefore I still don't understand it?
>
> Cor
>
Author
27 May 2006 5:48 PM
Martin Milan
"+Vice" <tonyp***@earthlink.net> wrote in
news:##6gMZYgGHA.4144@TK2MSFTNGP02.phx.gbl:

> We, for one, use this for code reusability, whereby all functions/subs
> that can throw an error will call a global error message handler that
> logs the message for troubleshooting when things goes wrong.  Can't
> always rely on the user to give us the details of the error.  With
> this we know where and when the error occurred.

Use Exceptions - you can get a full call stack...
Author
29 May 2006 1:48 AM
+Vice
You're probably right, I need to look into that, all I really need to see is
the function/sub where the error began.  I think the trouble I was having
with that, although I did not search deeper, was when a sub/function has an
error handler that calls a function that doesn't and so the call stack
incorrectly stated the function where the error was.  Anyway, I'll have to
research further just never bothered.

Show quoteHide quote
"Martin Milan" <I***@m.i.do> wrote in message
news:Xns97D0BF65EBFC8I8spmido@194.117.143.53...
> "+Vice" <tonyp***@earthlink.net> wrote in
> news:##6gMZYgGHA.4144@TK2MSFTNGP02.phx.gbl:
>
>> We, for one, use this for code reusability, whereby all functions/subs
>> that can throw an error will call a global error message handler that
>> logs the message for troubleshooting when things goes wrong.  Can't
>> always rely on the user to give us the details of the error.  With
>> this we know where and when the error occurred.
>
> Use Exceptions - you can get a full call stack...
Author
29 May 2006 11:54 AM
Brahm
My intention is make error handler re-usable and generic.

Thanks.

BRAHM


"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> escreveu na mensagem
news:%23VMQe9VgGHA.3984@TK2MSFTNGP02.phx.gbl...
Brahm,

You found your answer, but I am always curious why somebody needs this kind
of information, while he is in fact in the sub?

Cor

Show quoteHide quote
"Brahm" <daniel.br***@contronic.com.br> schreef in bericht
news:O9gn43PgGHA.4708@TK2MSFTNGP04.phx.gbl...
> Hey Guys!
>
>    is there anyway to get in runtime current function or sub name ?
>
> Daniel
>
>