How do I find out what class called me

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to write an error handler for my project. I would call this handler
and have it print a message. What I'd like to be able to do is to have the
handler know which class called it. Also, since the class that called it may
have been passed bad data from another class, I'd like to pass the name of
the other class also (if applicable).

So, suppose Class A instantiates Class B. Can Class B know who Class A is
without Class A passing that information as a parameter?

I'd appreciate any suggestions or advice.

Art
 
Art said:
Hi,

I want to write an error handler for my project. I would call this handler
and have it print a message. What I'd like to be able to do is to have the
handler know which class called it. Also, since the class that called it may
have been passed bad data from another class, I'd like to pass the name of
the other class also (if applicable).

So, suppose Class A instantiates Class B. Can Class B know who Class A is
without Class A passing that information as a parameter?

I'd appreciate any suggestions or advice.

Art


dim st as new stacktrace


Have a look at st.framecount and st.getframe and all the members of the
returned objects including the type information you get from them. See also
System.Reflection.MethodBase.GetCurrentMethod

Armin
 
Art said:
Hi,

I want to write an error handler for my project. I would call this handler
and have it print a message. What I'd like to be able to do is to have the
handler know which class called it. Also, since the class that called it may
have been passed bad data from another class, I'd like to pass the name of
the other class also (if applicable).

So, suppose Class A instantiates Class B. Can Class B know who Class A is
without Class A passing that information as a parameter?

I'd appreciate any suggestions or advice.

Art


I should add: When throwing an exception, you already have a stacktrace.


Armin
 
dim st as new stacktrace
Have a look at st.framecount and st.getframe and all the members of the
returned objects including the type information you get from them. See
also System.Reflection.MethodBase.GetCurrentMethod

Wow, that's pretty badass. I am deeply impressed. I would never have
thought of that!
--
Peace & happy computing,

Mike Labosh, MCSD

"Mr. McKittrick, after very careful consideration, I have
come to the conclusion that this new system SUCKS."
-- General Barringer, "War Games"
 
Armin,

Thanks very much for the help. This is a whole new area for me so it's
going to take some time to figure it all out.

Art
 

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