write what line is work now

  • Thread starter Thread starter macneed
  • Start date Start date
M

macneed

Can i write what line is work now?

try
{
....

}
catch
{
console.writeline("at program.cs line {0}", XXX)
}

console.writeline("at program.cs line {0}", XXX)
how to write this line's number?
 
Change your code to:

try
{
....
}
catch (Exception e)
{
console.out.writeline("error {0} at {1}.", ex.Message, ex.StackTrace);
}
 
Peter said:
You can create a new StackTrace instance, call GetFrame() with the value
of 0, and then call GetFileLineNumber() on the StackFrame instance you
get back. That will give you the line of code that was used to create
the StackTrace.

If build for debug.

Arne
 

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