Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5961439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:57:54+00:00 2026-05-22T18:57:54+00:00

I am developing Windows Phone 7 Silverlight Application. I want to do Application Level

  • 0

I am developing Windows Phone 7 Silverlight Application. I want to do Application Level error handling instead of writing try…catch… in all methods. I need to extract Method Name, Class Name and Line Number where the actual error occurred. Below is the demo code. In Application_UnhandledException event, I am expecting Method = “GenerateError” and Class = “ExceptionTesting”. Also, I want to get LineNumber where the actual error occurred (this is not shown in code).

Code to generate Error:

public partial class ExceptionTesting : PhoneApplicationPage  
{
    // Generate Error to Test Exception Handling
    private void GenerateError()
    {
        Int16 i = Convert.ToInt16("test");
    }
}

Code that Handles Application Level Exception:

// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
StackTrace st = new StackTrace();

var query = st.GetFrames()         // get the frames
        .Select(frame => new
        {                   
            Method = frame.GetMethod(),
            Class = frame.GetMethod().DeclaringType
        });

foreach (var q in query)
{
    if (q.Method.Name.Contains("GenerateError"))
    {
        MessageBox.Show("Class: " + q.Class + ", Method: " + q.Method);
    }
}

if (System.Diagnostics.Debugger.IsAttached)
{
    // An unhandled exception has occurred; break into the debugger
    System.Diagnostics.Debugger.Break();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:57:55+00:00Added an answer on May 22, 2026 at 6:57 pm

    The Application_UnhandledException method is not called from your method where the exception happens, so new StrackTrace() will not be meaningful, as you have discovered.

    To get the stack trace for the place where the exception occurred, use e.Exception.StackTrace.
    Note that the real exception may be wrapped inside another exception, possibly several layers deep (e.Exception.InnerException).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an application for windows phone 7 and I want to access my
I am developing a Windows Phone 7 Silverlight application that currently displays a map
I am developing a windows phone application in visual studio (Silverlight in C#) and
I am developing Windows Phone 7 application (7.0) and want to take photo without
I am Developing Windows Form Application in .Net, I want to insert selected rows
I'm developing a Windows Phone application. Is there anyway to animate transition between phone
I'm developing a Windows Phone application . I have defined this on App.xaml: <nav:UriMapping
I'm developing a Windows Phone 7 application and I'm trying to change the look
I am developing an application for Windows Phone 7. I am trying to use
I am developing a windows mobile application in which I want to debug the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.