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 8251129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:08:17+00:00 2026-06-08T00:08:17+00:00

Consider this simple console application: using System; namespace Demo { class Program { static

  • 0

Consider this simple console application:

using System;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            throw new Exception();
        }
    }
}

I run this under the debugger in either Visual Studio 2010 or Visual Studio 2012 Beta.

When I do so, naturally the debugger stops at the exception. Ok so far.

But when I press F5 to continue (or choose Debug|Continue) it stops at the same exception again.
I have to stop debugging for the program to exit. I expected the program to exit when I pressed F5.

Does anyone know why it behaves the way that it does?

[EDIT]

I’ve marked a reply as an answer, but to see a weird consequence of the debugger’s behaviour, consider the following code:

using System;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            throw new Exception();
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Console.WriteLine("Unhandled Exception.");
        }
    }
}

Run this under the debugger and press F5 a load of times, then look at the output. You’ll see a lot of “Unhandled Exception” messages, despite the code only actually throwing it once. The debugger is causing the exception to be thrown multiple times! This is what I find strange.

  • 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-06-08T00:08:19+00:00Added an answer on June 8, 2026 at 12:08 am

    What did you expect?

    Consider the following method:

    private void Test()
    {
        throw new Exception();  
        int u = 4;
    }
    

    When the exception is thrown, the debugger allows you to navigate to the calling context to see if your program catches the exception. If it’s not the case, it never exits the Test method by skipping the exception, that’s why int u = 4; is unreachable.

    In your example, it’s the same:

    private static void Main(string[] args)
    {
        throw new Exception();
    
        // If I'm here, I will exit the application !
        // But this place is unreachable
    }
    

    You can’t exit the Main method scope because of your exception. That’s why you can’t exit your application while debugging using F5.

    If you have no debugger attached, your application will of course crash because of an unhandled exception, but this is another story.

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

Sidebar

Related Questions

Consider the following code: using System; using System.Runtime.InteropServices; namespace Demo { class Program {
Consider the following code: class Program { static void Main(string[] args) { Department deathStar
Consider this: #include <iostream> using namespace std; class A{ protected: void some_function(int params) {
Consider this simple example - public class Person { private String name; private Date
Consider this simple program. The program has two files: File Vehicle.java class Vehicle {
Consider the following code: namespace ConsoleApplication { using NamespaceOne; using NamespaceTwo; class Program {
consider this simple code {$APPTYPE CONSOLE} uses Rtti, SysUtils; type {$M+} TFoo = class
Consider this simple program: class Shape { public: virtual double getArea() = 0; };
Consider this simple AS3 class. package { import flash.display.Sprite; import flash.display.MovieClip; public class MySprite
Consider this code sample: public class Human { public string Value { get; set;}

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.