How to make C# application crash

2020-02-28 05:29发布

I want to test if My application crash dump can be debugged, so I need generate a crash dump of my application firstly, but I write it with C#, so anybody know how to trigger a crash.(In fact I test with many exceptions, unsafe code......, but don't get it). thanks ---- sorry, sorry,I just lost somethings: I build the application with unity3d, which will handle exceptions for me automatic, and generate a crash dump for me if application crash

thanks all for your answers, I just test all your methods in common c# application and all works, but not unity3d application written with C#, it seems unity3d do more, I think I need to email unity3d to get a answer. I will post here if I get it.

标签: c# unity3d crash
12条回答
一夜七次
2楼-- · 2020-02-28 06:09

A surefire way to do it is as follows:

ThreadPool.QueueUserWorkItem(new WaitCallback(ignored => 
{
   throw new Exception();
}));

All the others can be handled by the top level ApplicationDomain.OnUnhandledException and the like.

This one will kill it dead (assuming .NET 2.0+, and not using 'legacyUnhandledExceptionPolicy': http://msdn.microsoft.com/en-us/library/ms228965.aspx).

查看更多
Deceive 欺骗
3楼-- · 2020-02-28 06:10

The following will provide an unhandled exception and will ask for you to choose a debugger:

System.Diagnostics.Debugger.Launch()
查看更多
乱世女痞
4楼-- · 2020-02-28 06:14

Use below code to close the application.

Environment.Exit(1);    

Exit needs a parameter called exitcode. If exitcode=0 means there was no error. Supply a non-zero exit code to to reflect an error.

查看更多
对你真心纯属浪费
5楼-- · 2020-02-28 06:15
 int[] x = {0};
 int blah = x[2];

will cause an exception just as well

查看更多
劫难
6楼-- · 2020-02-28 06:20

Throw an exception :)

throw new Exception("Your exception here!");
查看更多
倾城 Initia
7楼-- · 2020-02-28 06:20

Another option is to call

System.Environment.FailFast("Error happened")
查看更多
登录 后发表回答