Try catch finally in C,
The block in try is a block that may cause errors. The block in catch is the block that will be executed when an error occurs. The block in finally is the block that will be executed no matter whether an error occurs or not.
Example program:
Using System; using System. collections. generic; using System. linq; using System. text; namespace Sample_01_CA {public class Complex {static void Main (string [] args) {int I = 2008; int j = 0; try {int result = I/j ;} catch {Console. writeLine ("J variable value is 0");} finally {Console. writeLine (j. toString ();} Console. read ();}};}
Program output:
The value of the J variable is 0.
0
Example program:
Using System; using System. collections. generic; using System. linq; using System. text; namespace Sample_01_CA {public class Complex {static void Main (string [] args) {int I = 2008; int j = 2; try {int result = I/j ;} catch {Console. writeLine ("J variable value is 0");} finally {Console. writeLine (j. toString ();} Console. read ();}};}
Program output:
0