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

  • Elly Awesome

    Elly Awesome

    15 ŞUBAT 2010
  • MaximumPCMag

    MaximumPCMag

    23 Temmuz 2010
  • Paste Magazine

    Paste Magazi

    28 AĞUSTOS 2008