How does the try catch finally block work?

后端 未结 6 1505
耶瑟儿~
耶瑟儿~ 2021-02-06 20:35

In C#, how does a try catch finally block work?

So if there is an exception, I know that it will jump to the catch block and then jump to the finally block.

6条回答
  •  無奈伤痛
    2021-02-06 21:26

            try
            {
                //Function to Perform
            }
            catch (Exception e)
            {
             //You can display what error occured in Try block, with exact technical spec (DivideByZeroException)
                throw; 
                // Displaying error through signal to Machine, 
                //throw is usefull , if you calling a method with try from derived class.. So the method will directly get the signal                
            }
    
            finally  //Optional
            {
                //Here You can write any code to be executed after error occured in Try block
                Console.WriteLine("Completed");
            }
    

提交回复
热议问题