JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

Standard Exception in c++ , std::exception , std::bad_alloc , Member functions , Example

std::exception , std::bad_alloc , Member functions , Example , Standard Exception in c++ :-
इससे पहले के article मे , c++ language मे munual Exceptions handeling को discuss किया है अब इस article मे , c++ language का stanadard Exceptions को discuss करेगे | c++ language मे , कुछ Exceptions को पहले से define किया गया है जिसे किसी प्रोग्राम मे डायरेक्ट ही use किया जाता है | इन Exceptions को standard Exceptions कहते है | इसके लिए Exceptions file को किसी प्रोग्राम  के header portion मे add किया जाता है | इसके बाद ही Exceptions को use किया जा सकता है | नीचे सभी Exception को discuss किया गया है :-Sr.No Exception & Description
1. std::exception
ये Exceptionsclass है जिसमे सभी standard C++ exceptions को define किया गया होता है |

2. std::bad_alloc
std::bad_alloc एक object है जिसे exceptions की तरह से किसी बलको मे फेके जाता है | ये exceptions तब execute होता है तब किसी variable के लिए space को allocate करने में failure आता है |

Member functions
इसमें निन्म member function होता है :-
constructor: इस use bad_alloc object को construct करने के लिए किया जाता है | ये constructor है |
operator : इसका use , किसी bad_alloc object को replace करने के लिए किया जाता है | ये public member function है |
what : इसमें  explanatory string को return किया जाता है |  ये public member function है |
std::bad_alloc::bad_alloc मे
bad_alloc();
इसका use किसी new bad_alloc object को construct करने के लिए किया जाता है जिसमे implementation-defined null-terminated byte string को what() function से throw किया जाता है |

std::bad_alloc::operator= मे
bad_alloc& operator=( const bad_alloc& other );
Parameters
other – इसमें किसी new object को assign किया जाता है |
Return value
*this

std::bad_alloc::what मे ,
Parameters
इसमें कोई nभी parameter नहीं  होता है |
Return value
इसमें pointer return होता है जो की किसी null-terminated string को point करता है इसमें किसी Exceptions की information होती है |

Example
Run this code
#include <iostream>
#include <new>
int main()
{
try {
while (true) {
new int[1000bl];
}
} catch (const std::bad_alloc& e) {
std::cout << “Memory Allocation failed: ” << e.what() << ‘\n’;
}
}
इसमें किसी integer मे alphanumerical value को assign किया जाता है |
3. std::bad_cast
इस type मे , किसी dynamic_cast को throw किया जाता है क्योकि dynamic_cast से किसी reference type के run time मे error occur हो जाती है | आगे के article मे dynamic_cast को भी discuss करेगे |
Member functions
इसमें निन्म member function होता है :-
constructor: इस use bad_cast object को construct करने के लिए किया जाता है | ये constructor है |
what : इसमें  explanatory string को return किया जाता है |  ये public member function है |
destructor : इसका use किसी constructor को destroy करने के लिए किया जाता है |
std::bad_cast::bad_cast मे
bad_cast();
इसका use किसी new bad_cast object को construct करने के लिए किया जाता है जिसमे implementation-defined null-terminated byte string को what() function से throw किया जाता है |
Example:
#include <iostream>
#include <typeinfo>
struct F { virtual ~Food() {} };
struct B{ virtual ~Bar() {} };
int main()
{
Bar b;
try {
Foo& f1 = dynamic_cast<Food&>(b);
}
catch(const std::bad_cast& exe)
{
std::cout << exe.what() << ‘\n’;
}
}
इसमें दो type को define किया है जिसमे एक food और दूसरा bar को define करता है | जब किसी एक type को दुसरे type मे assign किया जाता है और उस समय अगर exceptions आ जाता है तब इस प्रकार के type को call किया जाता है |

4 .std::bad_exception
इस प्रकार के stanadard exceptions type को किसी c++ प्रोग्राम मे unexpected exceptions को handel करने के लिए किया जाता है |
std::bad_exception को c++ प्रोग्राम मे निन्म condition मे use किया जाता है :-

1)अगर std::exception_ptr मे किसी exception के copy को catch किया है और अगर exception objectका copy constructor को std::current_exception से catch किया गया है तब और किसी एक और exception को throw किया गया है तब इस exception को catch करने के लिए इस  type को use किया जाता है |

2) जब किसी dynamic exception  के  specification को define नहीं किया जाट अहै तब  std::unexpected से इस exception को बार बार फेके जाता है और अगर इसके specification को throw किया जाता है तब  std::bad_exception, std::bad_exception  को use किया जाता है |

Member functions
इसमें निन्म member function होता है :-
constructor : इस use bad_exception object को construct करने के लिए किया जाता है | ये constructor है |
operator : इसका use , किसी bad_exception object को replace करने के लिए किया जाता है | ये public member function है |
what : इसमें  explanatory string को return किया जाता है |  ये public member function है |
std::bad_exception::bad_exception मे
bad_alloc();
इसका use किसी new bad_exception object को construct करने के लिए किया जाता है जिसमे implementation-defined null-terminated byte string को what() function से throw किया जाता है |

Example
#include <iostream>
#include <exception>
#include <stdexcept>

void unwantedexp() { throw; }

void first() throw(std::bad_exception)
{
throw std::runtime_error(“Frist Test”);
}

void  main()
{
std::set_unexpected(unwantedexp);
try {
first();
}
catch(const std::bad_exception& exe)
{
std::cerr << “Catch ” << exe.what() << ‘\n’;
}
}
इस article मे , c++ language के कुछ standard exceptions को discuss किया आब आगे के article मे कुछ और exceptions को discuss करेगे |

Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

7 hours ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week 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