Thursday, July 4, 2013

Explaination about try catch finally.

What is try catch in programming?

  Try {
  lines of code to execute
  some error or exception occurs in the code placed inside the try block
  Then to record the exception, to do some other even on the exception we use catch block
  recode the error and write to the log file

What is try catch finally in programming?

Finally block is to do some thing which must be done at anycast which means if the try block executes successfully the code inside finally
block must execute. if the code in try has some error and thows an exception to the catch block, after the execution of the catch block
the code inside finally must execute. what ever happens code inside finally will execute at the last(final).

How to use try catch in C#

    public void PrintNo(string no_string)
            int no = Convert.ToInt32(no_string);
        catch (Exception ex)
            Response.Write("The input format was wrong");
            Response.Write("Thanks for your Try");
Test and output Case 1
Output will be:
Thanks for your try
Test and output Case 2
Output will be:
The input format was wrong
Thanks for your try

No comments:

Post a Comment