1 Static voidMain (string[] args)2 {3 intx =0;4 Try5 {6 inty = -/x;7 }8 Catch(Exception e)9 {Ten Console.WriteLine (e.message); One //throw;//throw out an exception A } - finally - { theConsole.WriteLine ("Anyway,we arrive here"); - } - Console.readkey (); +}
Exception classes for 2.c#
1 varAE =NewArgumentException ();//parameter Exception class2 varAne =NewArgumentNullException ();//parameter is an empty exception3 varAore =NewArgumentOutOfRangeException ();//parameter exceeds range exception4 varDne =NewDirectoryNotFoundException ();//IO exception path not found5 varFne =NewFileNotFoundException ();//File not found6 varIoE =NewInvalidOperationException ();//operator Exception7 varNIE =NewNotImplementedException ();//method Call Exception
3.c# Handling Exceptions
If the logical execution of the IF statement is much faster than the exception execution, then in the actual development process generally at the bottom of the use of Try catch, at the top of the business to prevent error causes the business to crash, also use try catch.
Basic syntax for exception handling in C #