Answers for "try and catch block"

6

try catch exception

First try block try to handle it
if not then catch block will handle it.
Finally block will executed regardless
of the outcome
Posted by: Guest on January-05-2021
-1

try catch block

const input = require('readline-sync');

let animals = [{name: 'cat'}, {name: 'dog'}];
let index = Number(input.question("Enter index of animal:"));

try {
   console.log('animal at index:', animals[index].name);
} catch(err) {
   console.log("We caught a TypeError, but our program continues to run!");
   console.log("You tried to access an animal at index:", index);
}

console.log("the code goes on...");
Posted by: Guest on May-24-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language