Answers for "try finally"

0

try-catch-finally

localStorage.getItem(key)

    try {
        data = JSON.parse(key)
    }
    catch (e) {
        // if the code errors, this bit of code will run
    }
    finally {
    
        return data
    }
Posted by: Guest on April-26-2021
0

try catch finally example

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
  }
}
Posted by: Guest on June-08-2021
0

Using try with finally block

#!/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')
Posted by: Guest on November-03-2021

Browse Popular Code Answers by Language