• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3. The JavaScript Language: Loop... > Using the try…catch Statement

Using the try…catch Statement

When you enclose a series of statements in a try statement, any error that happens when executing those statements will throw (that is, cause) an exception. When an exception is thrown, JavaScript will terminate the try statement and look for a catch statement, which “catches” the exception. If there is a catch statement, the code in that catch statement is executed, enabling you to deal with the error. There is also an optional finally statement, which is executed whether or not an exception occurs; here’s the syntax:

try { 
    tryStatements 
} 
[catch (exception) 
    {catchStatements}] 
[finally {finallyStatements}] 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint