Share your knowledge with other learners . . . Login Register

c++ Exception Handling In Hindi

📔 : C++ 🔗

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/terminate करती हैं।

c++ types of error

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

c++ Syntax Error

C++ में Syntax Errors program में syntax सही न होने के कारण आती हैं , इन्हे compile time error भी कहते हैं जो कि compile time पर आती हैं।
For Example -

CopyFullscreenClose FullscreenRun
#include <iostream>
int main() {
  // here we forgot to use semicolon;
  std::cout << "Hello world!"
  return 0;
}
Output
error: expected ';' before 'return'

ये errors program में होने पर हम , program को run करना तो दूर compile भी नहीं कर सकते हैं।

c++ Runtime errors

Runtime Errors , program के running time पर आती हैं , run time errors को ही exceptions कहते हैं। और सिर्फ इन्ही errors को हम handle कर सकते हैं।

c++ Logical Errors

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

CopyFullscreenClose FullscreenRun
#include <iostream>
using namespace std;
int main() {
  // here we have put semicolon just after the for loop
  for(int i=1; i>=5; i++);{
    cout << "It will print only once";
  }
  return 0;
}
Output
It will print only once

ऊपर दिए गए example में हमने for loop के just बाद semicolon ; लगा दिया है तो syntactically हमारा program सही है , but programmatically हमें desired output नहीं मिलेगा , क्योंकि loop हमें पहले ही close कर दिया है।

How to handle?

जब भी program में Run Time Error / Exception आती है , तो C++ इन errors का Object create करती है।Run Time Error / Exception को handle करने के लिए JavaScript हमें कुछ important statements provide कराती है - जिन्हे हम next topic में discuss करेंगे ।

  • try. . .catch .. .throw

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers