Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Exceptional Exceptions

Exceptional Exceptions

Scheduled Pinned Locked Moved C#
csharpgraphicsgame-devdockerdata-structures
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    inyoursadachine
    wrote on last edited by
    #1

    Hi, My understanding of the way exception work in .NET is that once an exception is thrown, the run-time unwinds the call stack until either (a) the call stack is empty (game over) or... (b) a catch block is found that "handles" the thrown exception I tested this my understanding of this with the program below. And just as I thought it would, after level5() through the exception the Runtime unwound the call stack back to level1(). My understanding is that the objectless "catch" will catch -ALL- exceptions. Period. Even unmanaged exception one of my books says. So... if I define my static Main() as: static void Main() { try { Application.Run(new Form1()); } catch { MessageBox.Show("Not so fast!"); } } ... is it possible for an (some) execptions to "leak" out to the Runtime? Thanks, Cunfewsdish =============================================================== using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Exceptional.cs { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // level1(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300,300); this.Text = "Form1"; } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void level1() { try { level2(); } catch { MessageBox.Show("Kawt!", "Level 1"); }

    D 1 Reply Last reply
    0
    • I inyoursadachine

      Hi, My understanding of the way exception work in .NET is that once an exception is thrown, the run-time unwinds the call stack until either (a) the call stack is empty (game over) or... (b) a catch block is found that "handles" the thrown exception I tested this my understanding of this with the program below. And just as I thought it would, after level5() through the exception the Runtime unwound the call stack back to level1(). My understanding is that the objectless "catch" will catch -ALL- exceptions. Period. Even unmanaged exception one of my books says. So... if I define my static Main() as: static void Main() { try { Application.Run(new Form1()); } catch { MessageBox.Show("Not so fast!"); } } ... is it possible for an (some) execptions to "leak" out to the Runtime? Thanks, Cunfewsdish =============================================================== using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Exceptional.cs { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // level1(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300,300); this.Text = "Form1"; } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void level1() { try { level2(); } catch { MessageBox.Show("Kawt!", "Level 1"); }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      If there is an Exception in the Runtime itself, it may crash your app, but an exception from inside your app can't leak out to the Runtime if you have an expcetion handler in place to grab it. There is an exception though. Not all exceptions will propogate up the call stack. The .NET Framework wraps and applications message pump in an exception handler. If an exception is generated that the application code doesn't handle, the exception handler around the message pump will handle it. For an example, you have two forms, one is your main form and the other is a dialog form. This means an exception generated in the dialog form will NOT propogate up to the main form that Show()'d it. Understand? If not, check this[^] article on MSDN for a quick example demonstrating this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      I 1 Reply Last reply
      0
      • D Dave Kreskowiak

        If there is an Exception in the Runtime itself, it may crash your app, but an exception from inside your app can't leak out to the Runtime if you have an expcetion handler in place to grab it. There is an exception though. Not all exceptions will propogate up the call stack. The .NET Framework wraps and applications message pump in an exception handler. If an exception is generated that the application code doesn't handle, the exception handler around the message pump will handle it. For an example, you have two forms, one is your main form and the other is a dialog form. This means an exception generated in the dialog form will NOT propogate up to the main form that Show()'d it. Understand? If not, check this[^] article on MSDN for a quick example demonstrating this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        I Offline
        I Offline
        inyoursadachine
        wrote on last edited by
        #3

        Thanks Dave. I was not aware that .NET wrapped each msg pump with an exception handler although that makes good sense. Is it possible to instruct (using your example of 2 forms, main and dialog) the dialog's wrapped exceptional handler to "hand off" caught exceptions back to the main form's code? TIA, Matt

        D 1 Reply Last reply
        0
        • I inyoursadachine

          Thanks Dave. I was not aware that .NET wrapped each msg pump with an exception handler although that makes good sense. Is it possible to instruct (using your example of 2 forms, main and dialog) the dialog's wrapped exceptional handler to "hand off" caught exceptions back to the main form's code? TIA, Matt

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          No, it's not. The message pump handler can't be bypassed, unfortunately, and it's behavior is to put up the usual message box you see for an "unhandled" exception. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups