xxxxxxxxxx
#!/usr/bin/env python3
try:
num = int(input("Enter the number: "))
re = 100/num
except:
print("Something is wrong")
else:
print("result is ",re)
finally :
print("finally program ends")
print('END')
xxxxxxxxxx
localStorage.getItem(key)
try {
data = JSON.parse(key)
}
catch (e) {
// if the code errors, this bit of code will run
}
finally {
return data
}
xxxxxxxxxx
try {
tryCode - Code block to run
}
catch(err) {
catchCode - Code block to handle errors
}
finally {
finallyCode - Code block to be executed regardless of the try result
}
xxxxxxxxxx
try {
myroutine(); // may throw three types of exceptions
} catch (e) {
if (e instanceof TypeError) {
// statements to handle TypeError exceptions
} else if (e instanceof RangeError) {
// statements to handle RangeError exceptions
} else if (e instanceof EvalError) {
// statements to handle EvalError exceptions
} else {
// statements to handle any unspecified exceptions
logMyErrors(e); // pass exception object to error handler
}
}