SORU
25 Temmuz 2010, Pazar


C# özel durum hangi elde satır numarası

catch bir blok içinde, nasıl bir özel durum hangi satır numarasını alabilir miyim?

CEVAP
25 Temmuz 2010, Pazar


Eğer sadece daha fazla izleme biçimlendirilmiş yığın satır numarasını ihtiyacınız varsa İstisna olsun.StackTrace, StackTrace sınıfını kullanabilirsiniz:

try
{
    throw new Exception();
}
catch (Exception ex)
{
    // Get stack trace for the exception with source file information
    var st = new StackTrace(ex, true);
    // Get the top stack frame
    var frame = st.GetFrame(0);
    // Get the line number from the stack frame
    var line = frame.GetFileLineNumber();
}

Bu eğer bir pdb dosyası Meclisi varsa orada sadece çalışacağını unutmayın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BenjiManTV

    BenjiManTV

    20 Mart 2011
  • hockeywebcasts

    hockeywebcas

    31 EKİM 2012
  • Roger Huffman

    Roger Huffma

    4 ŞUBAT 2007