Exiting a console app from deep in the code

Mar 23 2017 1:49 PM

I have a FATAL error that can occur deep in the code of a single-threaded background console app that was written in C# 4. Is there any advantage or disadvantage to calling Environment.Exit(1) right there, or is it better to  percolate an Exception all the way to int main() and call return(1)? The former seems direct and quick, while having an Exception wending its way up the stack trace seems like extra processing if it doesn't give me any advantages.

Technical answers are welcome. I have programmed for 37 years in C, 32 in C++, and 20 in Java, but am just past newby status in C#.


Answers (2)