|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Identifying the method and class name programmaticallyIs there any way to tell, programmatically, what method and class
you're in? For example, if I'm doing error handling, I don't want to have to type the name of the method and class each time; I'd rather have a stock thing I can just paste in everywhere. Thanks, Lisa A certain amount of this information is automatically processed and added to
the exception objects. Look, for example, at exceptionObject.StatckTrace, which contains the error point, as well as the entire stack trace a called b which called c which called d. -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA http://gregorybeamer.spaces.live.com ************************************************* Think outside of the box! ************************************************* <l***@starways.net> wrote in message news:1160055928.399442.73850@m7g2000cwm.googlegroups.com... > Is there any way to tell, programmatically, what method and class > you're in? For example, if I'm doing error handling, I don't want to > have to type the name of the method and class each time; I'd rather > have a stock thing I can just paste in everywhere. > > Thanks, > Lisa > A a = new A();
a.Function_1(0); class A { public A() { } public void Function_1(int d) { try { double c = 5/d; } catch (Exception e) { MessageBox.Show( " ERROR IN CLASS '" + this.GetType().Name + "' ON FUNCTION '" + e.TargetSite + "'"); } } } Regards Nicolas Guinet <l***@starways.net> a écrit dans le message de news: 1160055928.399442.73***@m7g2000cwm.googlegroups.com... Show quote > Is there any way to tell, programmatically, what method and class > you're in? For example, if I'm doing error handling, I don't want to > have to type the name of the method and class each time; I'd rather > have a stock thing I can just paste in everywhere. > > Thanks, > Lisa > Thank you so much!
Lisa Nicolas Guinet wrote: Show quote > A a = new A(); > a.Function_1(0); > > > class A > { > public A() { } > public void Function_1(int d) > { > try > { > double c = 5/d; > } > catch (Exception e) > { > MessageBox.Show( " ERROR IN CLASS '" + this.GetType().Name + > "' ON FUNCTION '" + e.TargetSite + "'"); > } > > } > } > > Regards > > Nicolas Guinet > > <l***@starways.net> a écrit dans le message de news: > 1160055928.399442.73***@m7g2000cwm.googlegroups.com... > > Is there any way to tell, programmatically, what method and class > > you're in? For example, if I'm doing error handling, I don't want to > > have to type the name of the method and class each time; I'd rather > > have a stock thing I can just paste in everywhere. > > > > Thanks, > > Lisa > > |
|||||||||||||||||||||||