Header Ads Widget

Ticker

6/recent/ticker-posts

Exception Handling In Java Full Details All Rules In HINDI

Exception Handling In Java Full Details All Rules In HINDI


आज हम एक्सेप्शन हैंडलिंग के बारे में पढेंगे .जब भी हम programming करते हैं उसी time हमारी गलती से error होता है

Error को हम दो categories में divide कर दिया हूँ -

1-Compile Time Error

Compile Time Error जब compiler दुआर code compile होता है , उसी time यदि कोई error आता है तो उसे compile time error कहते हैं .जितने भी syntax Mistake हैं यह सब compile time error हैं .

Example-

class Nimai{

Int 10

}

जैसे आप , ; "Nimai यह सब जब आप mistake करते हैं तो जब code compile होता हैं तब वह error दिखता है .और हामारा .class फाइल generate नही होता है .

2-Run Time Error

जब हामारा program syntax ठीक होता है और .class file generate होजाता है .उसके बाद जब हम run कराते हैं तब यदि error दिखाता है तो इसे runtime error कहते हैं .इसका बजह होती है logically जो हम code लिखते हैं उसमे गलती होती हैं इसीलिए वह error दिखता हैं .

यह runtime time error के time पर एक exception object create होता है इसे handle करने केलिए हम कुछ code लिखते हैं ताकि program की बाकी code जो है वह run हो सकें .इसे हम exception handling कहते हैं .exception handling एक process में होता है तो चलिए देखते हैं -

Exception Handling Process


Exception Handling को दो catagorie में  divide है -

1st Categories-

1-Hit the Exception

2-Throw the Exception

2nd Categories-

3-Catch the Exception

4-Handle the Exception

try Block-(Exception Object Creator)

इसमें जो code exception दिखा सकता है उसको यहाँ पर लिखना होता है .

Catch  Block-(Exception handler)

इसमें वह code लिखा जाता है वह जो exception आएगा try block से  उसे handle करने केलिए .

try{

statement;

}

catch(Exception type object)

{

statement;

}

देखिये जो भी try की दुआर  exception object throw होगा  यदि यह exception object  catch exception object से मिलता है तो वह try का statement execute होगा साथ में बाकी statement भी execute होगा .नही तो बाकी exception execute होगा .

Control Flow in Try Catch


try{

statement1;

statement2;

statement3;

}

catch(X e){

statement4;

}

statement5;

Case1-यदि कुछ भी exception नही होता है तो 1,2,3,5 execute होगा .

Case2-यदि exception statement2 में होता है  and corresponding block के साथ matched होता है 1,4,5 execute normaly होगा .

Case-3 यदि exception statement2 में होता है  and corresponding block के साथ matched होता है 1, execute होगा abnormaly .

Case-4 यदि exception statement 4 and 5 में होता है तो पूरा

More Article

Post a Comment

0 Comments