From 17d73ed8b75c9adf3d3065c50e2278d7456b4c86 Mon Sep 17 00:00:00 2001 From: tabishmemon <82882900+tabishmemon@users.noreply.github.com> Date: Sun, 31 Oct 2021 17:16:57 +0500 Subject: [PATCH] Add files via upload Error Handling in javascript --- ErrorHandling.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ErrorHandling.js diff --git a/ErrorHandling.js b/ErrorHandling.js new file mode 100644 index 0000000..362cae1 --- /dev/null +++ b/ErrorHandling.js @@ -0,0 +1,20 @@ + function greet_user(user) { + console.log('Hi ' + user.name + ', how are you?'); + } + + var user = { + 'name': "" + } + + try { + + if (!user.name) { + throw 'Name is empty'; + } + + greet_user(user); + + } catch (err) { + console.log(err); + console.log('Hi guest user, how are you?'); + }