Javascript & Python
In Python, we don't call it try-catch but rather try-except which works similarly to the try-catch in javascript and it is dedicated to error-handling.
PYTHON STRUCTURE
The program tries to run the code inside the try
block, if run fails, the exemption is raised in the except
block.
For example:
try:
print(x)
except:
print("Exemption: x was not defined. ")
The above python code will return an exemption:
Exemption: x was not defined.
JAVASCRIPT STRUCTURE
It is simple in javascript since error object array has message which summaries the whole error.
For example we want to print x in the console.
try {
console.log(x)
} catch (error) {
console.log(error.message);
}
The above javascript code will print:
x is not defined
Top comments (0)