हिंदी माध्यम नोट्स
Exception in c++ language in hindi , ofstream , ifstream , fstream , Exception Example
ofstream , ifstream , fstream , Exception Example , Exception in c++ language in hindi :-
इससे पहले के article मे , file handling को discuss किया था | अब इस article मे exception handeling को discuss करेगे | इससे पहले एक file handeling के सार को discuss करेगे |
file handling मे किसी file से data को read और write करने के operation को perform करने के method को discuss करते है | क्सिसी file को use करने एक लिए निन्म operation को perform करता है |
open an file : इस operation मे किसी file को open किया जाता है इसके लिए निन्म syntax को use किया जाता है :-
open();
इस file को open करने के लिए किया जाता है |
close() : इस function का use किसी file को क्लोज करने के लिए किया जाता है |
इसके अलावा निन्म command को use किया जाता है |
1. ofstream
इस data type क use output file stream के लिए किया जाता है | इस data type से file को create किया जाता है और इसमें केवल data को लिखा जाता है |.
2. ifstream
इस data type क use input file stream के लिए किया जाता है | इस data type से file को create किया जाता है और इसमें केवल data को पढ़ा जाता है |
3. fstream
इस data type को use file stream के लिए किया जाता है | इसमें ifstream और ofstream की तरह कार्य करता है | यानि इस data type का use किसी file को create , read और write करने एक लिए किया जाता है | समतातः इस data type का use ifstream और ofstream से ज्यादा किया जाता है |
इस article मे , exception handeling को discuss करेगे | जिसका use किसी c++ language मे काफी ज्यादा होता है |
exception एक problem है जो की किसी किसी प्रोग्राम के execution की समय generate होता है | c++ execution किसी exceptional circumstance(परिस्तिथि) मे प्राप्त होता है जब कोई प्रोग्राम run होता है | जैसे किसी प्रोग्राम मे 1 को 0 से divid करना |
exceptional का use प्रोग्राम के एक पार्ट सी control को प्रोग्राम के दुसरे प[art मे shift करने के लिए किया जाता है | c++ exception handling मे तीन keyword होते है :-
try , catch और Throw | इस keyword का use निन्म task के लिय किया जाता है :-
Throw : Throw keyword का use किसी exception को high ligth करने के लिए किया जाता है | जब किसी प्रोग्राम मे exception प्रॉब्लम आती है तब इस keyword को use किया जाता है |
catch : इस keyword से किसी प्रोग्राम मे से throw किसी गये exception को catch किया जाता है | अतः इस keyword से किसी प्रोग्राम मे से place को indentify किया जाता है झा पर exception को handel करना है | इस keyword का नाम catch इसलिए है क्योकि इस keyword का use किसी exception को catch करने के लिए किया जाता है |
try : इस keyword का use किसी प्रोग्राम के block को indetify करने के लिए किया जाता है जिसमे किसी exceptionको activate किया जता है | इस block मे एक या एक से ज्यादा catch statement हो सकता है |
उदाहरन के लिए किसी code block मे exception को generate किया जाता है | किसी method मे , किसीexception को catch करने के लिए try – catch statement को use किया जाता है | try/catch block को किसी प्रोग्राम block मे बीच मे execute किया जाता है | जिससे exception बन जाता है | किसी try/catch block मे declare किये गए block का mode protected होता है |the syntax for using try/catch निन्म है −
try {
// protected code
} catch( ExceptionName E1 ) {
// catch block
} catch( ExceptionName E2 ) {
// catch block
} catch( ExceptionName EN ) {
// catch block
}
Exception Example
जैसे की exception का उदाहरन निन्म है :
#include<iostream>
#include<conio>
using namespace std;
void main()
{
int a , b ;
a=0;
b=1;
int c = b/a ; // exception example
cout<<“Exception value : “<<c;
getch();
}
इस उदाहरन मे , जब 1 को 0 से divid किया जाता है तब infinite value मिलती है जो की c++ language मे exception को generate होता है |
exception handling का निन्म application होता है :
1. Error Handling code को Normal Code से Separation :
नोरमल programing code मे , error को handel करने के लिए if else statement को use करता है | इस method मे , error कपड़े नोरमल code मे मिक्स हो जाता है |और इस तरह का code less readable and maintainable होता है |try catch blocks से error code को नार्मल फ्लो से अलग किया जाता है |
2) Functions/Methods can handle any exceptions they choose:
किसी function मे एक या एक से ज्यादा exceptions होता है | लेकिन इसमें से कुछ ही को error handling मे use किया जाता है | जब किसी कॉलर किसी exceptionsको catch नहीं करता है जब exceptions को caller by caller catch किया जाता है |
c++ language , function को किसी exceptions को specify करने के लिए किया जाता है जिसे throw keywordसे प्रोगार्म से throw किया जाता है |
3) Grouping of Error Types:
c++ language , class का data type और object को किसी exceptions की तरह throw किया जाता है | इस तरह a hierarchy of exception objects, group exceptions in namespaces or classes को बना सकता है और इसके type की हिसाब इसे category भी कर सकते है |
इस article मे exception के basic को discuss किया है अब आगे के article मे advance concept को discuss करेगे |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…