Reputation: 2204
Quick one:
Is there any way in Visual Studio to make it so when my executable runs on client machines, instead of telling the user there is an uncaught exception, just quit quietly?
Note I want to be able to do this WITHOUT a try/catch... I know I SHOULD use a try/catch... I'm just wondering if there is a quick and dirty approach since the ideal behavior for the program is to just disappear if this particular exception is raised...
Code is in C#
Upvotes: 2
Views: 747
Reputation: 999
AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Environment.Exit(1); };
seems to do the trick. If you plonk this at the start of your entry point (or elsewhere), any unhandled exceptions that occur after this line has executed will trigger the program to exit with code 1. I think using try/catch in Main() is preferable to this though.
Upvotes: 3