Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Exception handling statement in javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 168
    Comment on it

    In JavaScript try/catch/finally are called exception handling statements. In JavaScript try/catch/finally statement manage some or all of the errors that might occur in a block of code. Try/catch/finally in JavaScript lets you deal with exceptions gracefully. In JavaScript code whenever the browser runs into an exception, while aborting the execution of the remaining code, it displays an error message to the user. You can put the code in try/catch/finally and handle the exception. Basically you have to use try/catch to try and run some code, and find the exceptions in the code.
    SYNTAX

    try {
        tryCode -The code which you want to try
    }
    catch(err) {
        catchCode - Block of code to handle errors
    } 
    finally {
        finallyCode - Block of code to be executed regardless of the try / catch result
    } 
    

    try statements The statements to be executed.
    catch(err) Statements that are executed if an exception is thrown in the try block.
    finally statements When the try statement completes these Statements that are executed . These statements execute regardless of whether or not an exception was thrown or caught.
    DESCRIPTION
    Exception handling consist of the try statement which consists of a try block, it contains one or more statements, and at least one catch clause or a finally clause, or both. Basically there are three forms of the try statement:

    • try...catch
    • try...finally
    • try...catch...finally
    • In JavaScript if an exception is thrown in the try block a catch clause contain multiple statements that specify us what to do next. User wants to succeed the try block, and if it does not succeed, it pass the control to the catch block.
      Within the try block if any statement throws an exception, control immediately shifts to the catch clause. In the try block if no exception is thrown, the catch clause gets skipped.

      After the execution of try and catch block the finally clause in JavaScript gets executed but before the statements following the try statement. The execution of try block is must, regardless of whether or not an exception is thrown or caught.

      You can use multiple try statements. If an internal try statement does not have a catch clause, the encompass try statement's catch clause is entered.

      JavaScript exceptions could be handled by the use of try statement.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: