Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silent exception,

I've encountered this weird issue of silent exceptions in 64 bit. What is that cause this bahavior? I would like to understand why does this occur and what is the recommended solution?

  • disappearing OnLoad exception
  • microsoft - silent exception
  • KB976038

on the main:

    try
    {
        Application.Run(new Form1());
    }
    catch
        (Exception ex)
    {
        MessageBox.Show("Error");
    }

private void Form1_Load(object sender, EventArgs e)
{
    throw new Exception("oh no!");
}
like image 643
user271077 Avatar asked Dec 21 '10 07:12

user271077


People also ask

What is a silent exception?

You can also define "silent" exceptions that do not, by default, cause the application to show the error message. Silent exceptions are useful when you don't intend to report an exception to the user, but you want to abort an operation.

What is exception and examples?

An event that occurs during the execution of a program that disrupts the normal flow of instructions is called an exception. Example: public static void Main ()

What does it mean to throw an exception?

In Java terminology, creating an exception object and handing it to the runtime system is called throwing an exception. After a method throws an exception, the runtime system leaps into action to try and find someone to handle the exception.

What is an exception text?

Exception Texts. Each exception is assigned a text that can be given parameters using attributes and that describes the exception situation. This text is displayed in the short dump of the runtime error if the exception is not handled.


1 Answers

In order to load a form, your code will call into a kernel function to create the form's window, and this kernel function will in turn call back into your code by sending a message that invokes your OnLoad method. If you throw an exception in that method, the exception handling mechanism walks the call stack back to the kernel mode boundary.

On x86 an exception can go through this boundary and back to the original caller. On x64 it stops when it hits the boundary and cannot continue. In XP64 and Vista the exception was swallowed (ignored), while a 64-bit app with a manifest saying it is Win7-compatible will crash when this happens. To get the crashing behavior on other OSes or for 32-bit apps on 64-bit Win7, see KB976038.

This behavior will happen for any event handler that is invoked as a callback from kernel mode on x64.

like image 187
Gabe Avatar answered Sep 18 '22 12:09

Gabe