Sunday, November 1, 2015

C# What are try, catch and finally

Its pretty simple again as the name suggests, 



Remember you shouldn't use a try catch block if you don't expect any errors in the first place

An example of try catch finally would be this;



     try
        {
            int a = 10;
            int b = 20;
            int z = a + b;
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            Console.WriteLine("Executed");
        }

No comments:

Post a Comment