In a winforms app, in a form's Load event, add the following line:
throw new Exception();
and run the application. It ran without a problem. This is called a silent failure, you can try to add messageboxes before and after, and you'll soon find out that instead of crashing the application, the throw statement just exits from the Load event.
I'm sure there is no need to explain how ugly and dangerous this is.
I was wondering nonetheless in the (probably history) reasons behind this terrifying behavior.
I'm sure it's not a design decision, probably no-choice, or laziness. Does anybody know?
Would be glad if anyone can point me to a list of events which may cause seilent failures too.
Here's a snippet of my code - I have no idea how it might help - but, here it is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Form f = new Form();
f.Load += new EventHandler((x, y) => { throw new Exception(); });
Application.Run(f);
}
}
}
EDIT
It seems it does not happend to everyone.
I use: fw 3.5, winforms, vs 2008, vista x64, new clean project of winforms, with the code mentioned above.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…