2
Reply

What is Try-Catch in .net?

Brijesh Jalan

Brijesh Jalan

14y
5.3k
0
Reply

    A Try Catch in .Net or any programming language main purpose is to handle the exceptions in a structured manner.
    Try
    {
     // We write the code to be executed
    }
    Catch(Exception Ex)
    {
         // To Handle the error
    }
    Catch(Exception Ex)
    {
        // To Handle Multiple exceptions of different types
    }

    If any error got handled then the execution exists or checks the next exception in nested block or also Nested Error ExceptionHandling
    Exception is the base Class for ExceptionHandling .For custom Exception handling in the application we need to inherit from BaseClass i.e., Exception

    Examples : IndexOutOfRangeException
    InvalidCastException
    ArgumentOutOfRangeException
    NullReferenceException

    Static class contain only static members(like variables,methods) on it.