Option 1. For a global solution within the entire application - at the start, we initialize the interception of exceptions:
namespace myApp { static class Program { static void Main(string[] args) { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); // здесь запускаемся... } } }
in the method we process the interrupt:
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { if (e.Exception as System.FormatException != null) { //TODO что-то Console.WriteLine(ex.Message); } }
Option 2. We can duplicate the TryParce mentioned above, but with our own implementation:
public static class MyParseClass { public static bool Parse(object inParam, out outParam) { try { outParam=int.Parse(Console.ReadLine()); return true; } catch (Exception ex) { outParam = 0; Console.WriteLine(ex.Message); return false; } } }
TryParse- MonkSystem.FormatException, then there should suddenly be an exception throw? Such an approach would be suitable for small programs, but it does not work at all for any large-scale projects. - VladD