JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

Standard exceptions in c++ language in hindi , std::bad_typeid , std::logic_error , std::domain_error

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 किया जाता है |
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 करेगे |

Sbistudy

Recent Posts

सारंगपुर का युद्ध कब हुआ था ? सारंगपुर का युद्ध किसके मध्य हुआ

कुम्भा की राजनैतिक उपलकियाँ कुंमा की प्रारंभिक विजयें  - महाराणा कुम्भा ने अपने शासनकाल के…

3 weeks ago

रसिक प्रिया किसकी रचना है ? rasik priya ke lekhak kaun hai ?

अध्याय- मेवाड़ का उत्कर्ष 'रसिक प्रिया' - यह कृति कुम्भा द्वारा रचित है तथा जगदेय…

3 weeks ago

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

2 months ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

2 months ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

2 months ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

2 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now