using System; class Program { static void Main() { Console.WriteLine("Program is running"); Environment.Exit(0); Console.WriteLine("Program has exited"); } }
using System; class Program { static void Main() { Console.WriteLine("Program is running"); try { int n = Convert.ToInt32("not a number"); Console.WriteLine("This line of code will never be reached"); } catch (FormatException ex) { Console.WriteLine(ex.Message); Environment.Exit(1); } } }In this example, the program attempts to convert the string "not a number" to an integer, which will cause a FormatException. The program catches the exception, prints out the error message, exits the program with the exit code 1, and skips any remaining lines of code. Package library: System.Runtime.Extensions.