How to Dump Data Causing FormatException?

  • Thread starter Thread starter samueltilden
  • Start date Start date
S

samueltilden

When I catch a System.FormatException, the most information it gives
me is:

"The string was not recognized as a valid DateTime."

What is "the string" (i.e., its value)?

How can I find out, programmatically within the catch block, what the
actual value of the string is?

P.S. I've tried to dump out the MethodBase TargetSite of the exception
but did not (yet) find the data causing the exception.

Thanks.
 
One additional piece of information:

When I do dump out the MethodBase TargetSite, I can get the input
parameters of the Parse() function, especially the first paremeter,
"string s". I tried to get the actual value of the parameter "s"
passed into this Parse() function, but have not yet been successful.

Do you think that this approach will eventually yield the value of the
bad data, or is there some totally different approach?

Thanks.
 
There really isn't any way to do that. You have to be aware of where
the exception was thrown, and the string that was passed to whatever method
threw it.
 
No, it won't, as the MethodInfo (and ParameterInfo instances) only tell
you about the structure of the method, they don't actually have access to
any of the data of the method when it is running (since any thread at any
time can run the method, how would you be able to get it from a single entry
point?).
 

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

Similar Threads


Back
Top