#JS-Fundamental
#Javascript
Exception
- An exception signifies the presence of an
abnormal condition
which requires special operable techniques
- Error Types
- Syntax Error
- Mistake in the pre-defined syntax
- Runtime Error
- Runtime errors are known as
Exceptions
.
- Logical Error
- Logical mistake in the program,
abnormal output
Exception Handling
try
- The code in try {…} is executed.
catch
- This Statement is executed if an exception is thrown in the try-block.
exception_var
- An optional identifier to hold an exception object for the associated catch-block.
finally
- Statements that are executed after the try statement completes.
- These statements execute
regardless exception was thrown or caught
throw
- The throw statement defines a custom error
try {
try_statements
}
catch (exception_var) {
catch_statements
}
finally {
finally_statements
}
try {
// generates an exception
throw 'myException';
} catch (e) {
// statements to handle any exceptions
console.log(e);
} finally {
console.log('finally');
}
// myException
// finally