Home PowerShell Internals Debugger Intentionally Crashing PowerShell

Intentionally Crashing PowerShell

If you must crash a PowerShell script (or the ISE editor), for example to test some error reporting or logging, it’s not easy these days to make something crash. Which is why there is a built-in crash function you can use:



  This will cause a certain crash

The moment you call this from within PowerShell, your host will freeze and crash, and Windows Error Reporting kicks in. The message you specify is written into the Application log and included in Error Reporting.

The FailFast() method itself does have a serious background, too:

If you detect that your “application” (aka script) is seriously seriously seriously damaged, and you want to exit immediately without doing one more thing (and risking damage due to corrupted state or variables), then FailFast() is the right thing to call. If you’d instead use Exit, then all possibly pending finally() code blocks would still continue to execute.