use try_catch exception to catch wrong entry or calculation or error; however does protect from the no entry error |
![]() |
![]() |
Now let us try to use a key word that will allow us wrong entries at the command prompt |
using System; //handle System.FormatException generated from //not entering the feed to Console.ReadLine() at the command prompt //csc catch_formatexception.cs class test { static void Main() { Console.Write("Please enter a number :"); string str = Console.ReadLine(); int n; try { n = Int32.Parse(str); Console.WriteLine("Here Number your entered no problem"); } catch(Exception ex) { Console.WriteLine("looks like you missed something :"+ str + " you may use ex to complete result" ); } } } |
![]() ![]() ![]() ![]() |
You may visit the ugly error alert Link |