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

  • Home
  • SEARCH
  • 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 762813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:27:19+00:00 2026-05-14T16:27:19+00:00

Possible Duplicate: Show line number in exception handling Can someone please tell me how

  • 0

Possible Duplicate:
Show line number in exception handling

Can someone please tell me how to get the line number of the code where the error occurred and display it to the console?

Other information like the file name or method name would be very handy.

  • 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-14T16:27:20+00:00Added an answer on May 14, 2026 at 4:27 pm

    You can print the entire stack trace by using a try/catch around the code that can throw and then using Console.WriteLine to show the exception object:

    try
    {
        new Program().Run();
    }
    catch (Exception exception)   // Prefer to catch a more specific execption.
    {
        Console.WriteLine(exception);
    }
    

    Output:

    System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at Program.Run() in C:\Console Application1\Program.cs:line 37
       at Program.Main(String[] args) in C:\Console Application1\Program.cs:line 45
    

    The first line shows the type of the exception and the message. The second line shows the file, function and line number where the exception was thrown. You can also see the locations of other calls on the call stack in the following lines.

    You can also get file and line numbers for uncaught exceptions. You can do this by adding a handler for the AppDomain.UncaughtException event on the current AppDomain:

    static void Main(string[] args)
    {
        AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        new Program().Run();
    }
    
    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        Console.WriteLine(e.ExceptionObject);
    }
    

    This shows a similar output to above.

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

Sidebar

Related Questions

Possible Duplicate: What is dependency injection? Spring uses dependency injection pattern. Can someone show
Possible Duplicate: How can I use delay() with show() and hide() in Jquery How
Possible Duplicate: How can I get this ASP.NET MVC SelectList to work? What the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: What's the best way to grab/parse command line arguments passed to a
Possible Duplicate: Convert some code from C++ to C I've got some code that
Possible Duplicate: How to change button text for Yes & No buttons on MessageBox.Show
Possible Duplicate: How can I use a carriage return in a HTML tooltip? I'd
Possible Duplicate: What's wrong with Delphi's “with” I am have a problem debugging code
Possible Duplicate: How do you count the lines of code in a Visual Studio

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.