Define your own anomaly in C #

xiaoxiao2021-03-06  49

In addition to predefined abnormalities, we can also create our own exception. The process is relatively simple: (i)) A abnormal declaration: Class ExceptionName: Exception {} (ii) THROW (ExceptionName); look Example: class iemsecondgrade: system.exception {} // Declaration exception class secondgrade {public static int mul (int first Abnormally returnis;} public static void main () {int mul_value; try {mul_value = mul (99,56); system.console.writeline ("99 and 56 accumulation: {0}", mul_value) Mul_Value = MUL (101, 4); System.Console.writeline ("Exception, this line is not executed.");} catch (} catch ({iamsecondgrade) // capture custom exception {system.console.writeline ("I only last the second grade, more than 100 multiplication, I won't. Hey, I have a customized exception.");} Catch (system.exception e) {system.console.writeline ("Non-custom anomaly. To: {0} ", e);}}}

转载请注明原文地址:https://www.9cbs.com/read-115626.html

New Post(0)