Standard exceptions in c++ language in hindi

std::bad_typeid , std::logic_error , std::domain_error , Standard exceptions in c++ language in hindi :- इससे पहले के article मे , c++ language के कुछ Standard exceptions को discuss किया था अब इस article मे c++ लंगुगे के कुछ और v को discuss करेगे |

  1. std::bad_typeid
    इस प्रकार का exceptions को तब use किया जाता है जब किसी id का type मे error आ जाती है | या integer id type मे characeter id को असिग्न करने की कोशिश की जाती है | यस इस type को तब use किया जाता है जब किसी typeid को किसी null pointer के लिए reference के लिए use किया जाता है |
    इसमें निन्म member function होते है :-
    1. destruction () : इस function का use किसी class के लिए destruction की तरह कार्य करता है |
    2. Costruction(): इस function का use किसी class के लिए Costruction की तरह कार्य करता है |
    3. what() : इसमें  explanatory string को return किया जाता है | जो की error message को hold करता है | ये public member function है |
    उदाहरन :
    #include <iostream>
    #include <typeinfo>

struct S { // The type has to be polymorphic
virtual void f();
};

int main()
{
S *p = nullptr;
try {
std::cout << typeid(*p).name() << ‘n’;
} catch(const std::bad_typeid& exp) {
std::cout << exp.what() << ‘n’;
}
}
इस उदाहरन मे string s को define किया गया है और इसके बाद string type के एक object pointer p को define किया गया है और इसके बाद इस pointer exceptions को call किया जाता है |

2. std::logic_error
इस प्रकार के object को तब throw किया जाता है जब किसी प्रोग्राम मे गलत लॉजिक को use किया जाता है | इस type मे error को रिपोर्ट किया जाता है जो की किसी किसी प्रोग्राम मे faulty लॉजिक के कर्ण होता है | इसके लिए c++ class मे पहले से logical preconditions or class invariants होते है जिससे सभी लॉजिक को compare किया जाता है |
इस library component मे exception को throw directly नहीं किया जाता है तब exception type std::invalid_argument, std::domain_error, std::length_error, std::out_of_range, std::future_error, and std::experimental::bad_optional_access और std::logic_err से प्राप्त किया जाता है |

3. std::domain_error
इस प्रकार के exception को जब throw किया जाता है तब mathematically invalid domain को use किया जाता है |

4. std::invalid_argument
इस प्रकार के exception को जब throw किया जाता है तब invalid arguments को use किया जाता है |
इससमे भी constructor, what और destructor function होते है जिनका रोल भी सभी statandard exception मे सामान रहता है |
#include <iostream>
#include <stdexcept>
#include <bitset>
#include <string>

int main (void) {
try {
std::bitset<5> mybitset (std::string(“952552525212”));
}
catch (const std::invalid_argument& exp) {
std::cerr << “Invalid argument: ” << exp.what() << ‘n’;
}
return 0;
}

4. std::length_error
इस exception को तब use किया जाता है जब बहुत बड़ी string को create किया जाता है | इसमें भी  constructor, what और destructor function होते है जिनका रोल भी सभी statandard exception मे सामान रहता है |
// length_error example
#include <iostream>       // std::cerr
#include <stdexcept>      // std::length_error
#include <length>         // std::length

int main (void) {
try {
// length throws a length_error if resized above max_size
std::length<int> length;
length.resize(length.max_size()+1);
}
catch (const std::length_error& lerror) {
std::cerr << “Length error: ” << lerror.what() << ‘n’;
}
return 0;
}

5. std::out_of_range
इस exception को तब use किया जाता है जब बहुत out ऑफ़ range की condition आ जाती  है | इसमें ‘at’ method को throw किया जाता है जैसे std::vector and std::bitset<>::operator[]()|इसमें भी  constructor, what और destructor function होते है जिनका रोल भी सभी statandard exception मे सामान रहता है |

6. std::runtime_error
इस error को theoretically explain करने मुश्किल है क्योकि इसमें लिए कोई भी फिक्स condition नहीं होती है  लेकिन किसी प्रोग्राम मे runtime_error आ जाती है तब इस प्रकार के exception को use किया जाता है |

7. std::overflow_error
इस प्रकार के exception को तब use किया जाता है जब किसी dynamic data type मे overfull condition आ जाती है | उदाहरन के लोइए
Stack मे दो प्रकार की exception होते है underflow और overflow होते है |
underflow : ये condition तब आती है जब stack मे pop operation को perform किया जाता है | इस operation मे stack मे से data item को डिलीट किया जाता है | जब stack empty होते है तब इस exception को use किया जाता है |

Also read : Signals in c++ language in hindi


overfull :ये condition तब आती है जब stack मे push operation को perform किया जाता है | इस operation मे stack मे से data item को insert किया जाता है | जब stack full हो जाती  है तब इस exception को use किया जाता है |

8. std::range_error
इस exception का use तब किया जाता है जब किसी value को variable मे assign करने की कोशिश की जाती है और value , declare variable के range से बहार होती है |

9. std::underflow_error
इस प्रकार के exception को तब use किया जाता है जब किसी dynamic data type मे underflow condition आ जाती है | उदाहरन के लिए
queue मे दो प्रकार की exception होते है underflow और overflow होते है |
underflow : ये condition तब आती है जब queue मे delete operation को perform किया जाता है | जब queue empty होते है तब इस exception को use किया जाता है |

इस article मे c++ language के standard exception handeler को discuss किया है आब आगे के article मे exception handeling के उदाहरनो को discuss करेगे |

हम आशा करते है कि यह नोट्स आपकी स्टडी में उपयोगी साबित हुए होंगे | अगर आप लोगो को इससे रिलेटेड कोई भी किसी भी प्रकार का डॉउट हो तो कमेंट बॉक्स में कमेंट करके पूंछ सकते है |
आप इन्हे अपने Classmates & Friends के साथ शेयर कर सकते है |

Leave a Comment

Your email address will not be published. Required fields are marked *