JavaScript Exception Handling In Hindi

📔 : Java Script 🔗

Exception Handling , program में आयी unwanted errors को handle करने का एक process / method है। इन unwanted errorsकी वजह से कभी कभी program terminate हो जाता है।  हालाँकि program का terminate होना Exception पर depend करता है कि Exception किस तरह की है।

Understanding Exception : Exceptions कुछ unwanted events होती हैं , जो program execution के समय आती हैं और program को disrupts करती हैं।

JavaScript Types Of Errors

  1. Syntax Errors
  2. Run Time Errors
  3. Logical Errors

JavaScript Syntax Error

JavaScript में Syntax Errors program में syntax सही न होने के कारण आती हैं , इन्हे parse errors भी कहते हैं जो कि interpret time पर आती हैं।

For Example

<script type="text/javascript">
let x = "apple";
document.write(x;
/* It will generate error*/
Uncaught SyntaxError: missing ) after argument list
</script>

ऊपर दिए गए program में variable x के बाद parenthesis ) close न कारण syntax error आयी।


JavaScript Run Time Errors

Runtime Errors , program के running time पर आती हैं , run time errors को ही exceptions कहते हैं।

See Example

<script type="text/javascript">
/* calling a undefined method is a good example of runtime error */
myfun();

Uncaught ReferenceError: myfun is not defined
</script>

JavaScript Logical Errors

Logical Errors , program में apply किये गए logic में mistake की वजह से आती हैं। इन Logical Errors की वजह से हमें desirable output नहीं मिलता। Logical Errors को  बिना किसी tool के handle करना मुश्किल है।

For Example एक ऐसा loop जो कभी ख़त्म ही न हो

<script type="text/javascript">
/* a endless loop can terminate / destroy your program */
while(true)
{
document.write("Hello");
}
document.write("it will never print");
</script>

How to handle ?

जब भी program में Run Time Error / Exception आती है , तो JavaScript इन errors का Object create करती है। इस Error Object की दो property होती है

1. name - इस property की मदद से हम error का name set / get करते हैं।

2. message - और यह property string form में error message return करती है।


Run Time Error / Exception को handle करने के लिए JavaScript हमें कुछ important statements provide कराती है - जिन्हे हम next topic में discuss करेंगे ।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers