In this blog we will see what is try catch statement in Typescript.

Try catch Statement in TypeScript : 

The try catch statement in TypeScript allows you to handle some or all of the errors that may occur in your application. These errors are frequently referred to as exceptions. A try-catch statement contains a try block containing statements that may throw an exception. Then you write a catch block that contains the statements that are executed when any statement in the try block throws an exception. This is referred to as exception handling.

The catch block is used to catch exceptions that are thrown inside a try block. If not, the caller function receives the exception. Until the exception is caught or the application crashes due to a runtime problem, this exception passing process continues.

Syntax :
try {} catch (Exception ex) {}
We can also use the “finally”
block
for exception handling;
see: try {}
catch (Exception ex) {} finally {} 

The “finally” block will always be carried out.

Example : 

private handling(argument: string): string {

    try {

        result= this.markLibrary(argument);

    }

 catch(e:Exception){

        result = e.Message;

    }

    return result;

}

 

For any Help or Queries Contact us on info@crmonce.com or +918096556344