Try…Catch, Errors, & Exceptions

Video

JavaScript Notes

JavaScript
    // throwing Errors and Exceptions
    // and
    // using Try…Catch to handle thrown Errors and Exceptions
    // Error Types:
    // EvalError, InternalError, RangeError, ReferenceError  - built-in Error types
    // SyntaxError, TypeError, URIError – built-in Error types
    
    try{
         //throw "Javelin";   			// program stops running at this point
         //throw {name:'Bubba', message:'Salmon'};     //something you create is called an exception
         let url = http://jsonplaceholder.typicode.com;
         fetch(url).then( (response) => { }).
         // throw new Error(' A stick' );	// this is generic built-in Error object		
        console.log('Hello');
    } catch(err) {
         console.log('Caught', err.name, err.message);
    } finally {
         console.log('Took you a long time');	// runs regardless of whether there is an error or not
    }
    console.log('end');