Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throw exception to stop process

Tags:

c#

exception

Some times in C# I would like to throw an exception that cannot be handled. An escalated exception that results in the process being stopped. Is this possible?

like image 378
Matthew Avatar asked May 11 '26 16:05

Matthew


1 Answers

You could do something like:

class BadassException : Exception
{
  public BadassException(string message)
  {
    Environment.FailFast(message);
  }
}

...

throw new BadassException("Erk!!!");
like image 188
leppie Avatar answered May 13 '26 07:05

leppie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!