try statement defines a block of code that you want to try to execute, and use the
catch statement to define a block of code that will execute if an exception to the normal running of the code occurs in the block of code defined by the
The following are the key points to be noted while using
try catch statement.
try...catchstatements work as a pair; you can’t have one without the other.
- If no exception occurs inside the
tryblock, the code inside the catch statement is never executed.
catchstatement also enables you to get the contents of the exception message that would have been shown to the user had you not caught it first.
Without Using try catch Block
Unlike the above example, the following example throws an error and stop executing further.
Please do google search for:
Join Our Channel
This channel is primarily useful for Full Stack Web Developer.