PL/SQL Exception Handling in Hindi | एक्सेप्शन हैंडलिंग क्या है?

जब हम कोई प्रोग्राम लिखते हैं, तो कई बार कोड बिल्कुल सही होने के बावजूद run-time पर error आने के कारण प्रोग्राम रुक जाता है। इन errors को हैंडल करना ही Exception Handling कहलाता है।

PL/SQL में exception handling एक ऐसी प्रक्रिया है जो run-time errors को detect करके उन्हें handle करती है, ताकि प्रोग्राम बिना रुके सही तरीके से execute हो सके।

Exception क्या होता है?

PL/SQL में exception एक ऐसा error है जो program के execution के दौरान होता है और प्रोग्राम के normal flow को रोक देता है।

Exception प्रोग्राम चलने के समय होता है, न कि compile करते समय।

इसलिए इसे run-time error भी कहा जाता है।

 

PL/SQL में Exception Handling क्यों ज़रूरी है?

कारणविवरण
प्रोग्राम क्रैश होने से बचाता हैError आने पर program forcefully बंद होने से रोकता है
कस्टम मैसेज देता हैUser को meaningful error message दिखाता है
Data Loss रोकता हैTransactions को सुरक्षित करता है
Debugging आसान होती हैError की जानकारी मिलती है

 

PL/SQL Exception Handling का Structure

PL/SQL में exception को handle करने के लिए program में नीचे दिए गए sections उपयोग होते हैं:

DECLARE
   -- variable or exception declaration
BEGIN
   -- executable statements
EXCEPTION
   -- exception handling code
END;
/

Types of Exceptions in PL/SQL (PL/SQL में Exception के प्रकार)

PL/SQL में exceptions मुख्य रूप से दो प्रकार के होते हैं:

1. System Defined Exception (Predefined)

ये Oracle द्वारा पहले से बनाए गए होते हैं।
उदाहरण: NO_DATA_FOUND, ZERO_DIVIDE, TOO_MANY_ROWS

2. User Defined Exception

इनका निर्माण programmer खुद करता है, जब अपनी जरूरत के अनुसार custom error चाहिए हो।

System Defined Exception Handling Example

DECLARE
   v_name  student.name%TYPE;
BEGIN
   SELECT name INTO v_name FROM student WHERE id = 100;
   DBMS_OUTPUT.PUT_LINE(v_name);
EXCEPTION
   WHEN NO_DATA_FOUND THEN
      DBMS_OUTPUT.PUT_LINE('Record Not Found!');
END;
/

User Defined Exception कैसे बनाते हैं?

  • Step 1: Exception Declare करना
  • Step 2: Exception Raise करना (RAISE Command)
  • Step 3: Exception Handle करना

Example of User-Defined Exception

DECLARE
   age_limit EXCEPTION;
   v_age NUMBER := 15;
BEGIN
   IF v_age < 18 THEN
      RAISE age_limit;
   END IF;
   DBMS_OUTPUT.PUT_LINE('Eligible');
EXCEPTION
   WHEN age_limit THEN
      DBMS_OUTPUT.PUT_LINE('Not Eligible - Age Must Be 18+');
END;
/

Exception को RAISE_APPLICATION_ERROR से Raise करना

Oracle में custom error number और message देने के लिए:

 

PL/SQL Exception Handling के मुख्य Keywords

Keywordउपयोग
RAISEException को manually raise करना
WHENError condition define करना
OTHERSसभी unknown errors को handle करना
PRAGMA EXCEPTION_INITUnnamed exception को नाम देना
RAISE_APPLICATION_ERRORCustom error code और message देना

 

WHEN OTHERS का उपयोग कब?

यह वो सभी errors handle करता है, जिन्हें किसी specific नाम से catch न किया गया हो।

 
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Unexpected Error Occurred!');
ध्यान: इसे हमेशा सबसे आखिरी में ही रखा जाता है।
 

इन्हें भी पढ़े –

  1. DBMS क्या है DBMS के प्रकार और कार्य की पूरी जानकारी | DBMS In Hindi
  2. डेटाबेस यूजर्स क्या है?
  3. डेटा इंडिपेंडेंस क्या है
  4. DBMS के लाभ
  5. Characteristics Of DBMS In Hindi
  6. डेटा मॉडल क्या है?
  7. डेटाबेस स्कीमा क्या है
  8. इंस्टैंस क्या है
  9. डेटाबेस इंटरफ़ेस क्या है
  10. डेटाबेस लैंग्वेज क्या है
  11. Classification of DBMS in Hindi
  12. Entity Set in DBMS
  13. DBMS Architecture in Hindi
  14. Types of Data Models in Hindi
  15. Attributes in DBMS in Hindi
  16. Entity Set in DBMS (Hindi)
  17. Entity Types in DBMS (Hindi)
  18. Types of Attributes in DBMS
  19. ER Model in DBMS (E-R मॉडल) क्या है?
  20. Entities के बीच संबंध
  21. Domain in DBMS
  22. Tuples in DBMS
  23. SQL में Joins क्या हैं?
  24. Primary Key in DBMS
  25. DBMS Keys in Hindi
  26. DBMS Data Integrity in Hindi
  27. Relational Algebra in DBMS
  28. Normalization in DBMS क्या है?
  29. BCNF (Boyce-Codd Normal Form) in DBMS
  30. Functional Dependency in DBMS
  31. Non-Loss Decomposition in DBMS
  32. SQL Data Types in Hindi
  33. Create Table in SQL in Hindi
  34. SQL DROP TABLE और ALTER TABLE in Hindi
  35. SQL Indexes in Hindi
  36. SDLC in Hindi
  37. DBLC in Hindi
  38. SQL Views in Hindi
  39. PL/SQL PROCEDURES in hindi
  40. Database Normalization in Hindi
  41. Domain Key Normal Form in Hindi
  42. SQL Objects in Hindi
  43. Aggregation, Generalization, Specialization and Association in Hindi
  44. Data Dictionary क्या है?
  45. डेटा वेयरहाउसिंग क्या है?
  46. डाटा माइनिंग क्या है?
  47. File Organization in Hindi DBMS
  48. Relational Model in Hindi – रिलेशनल मॉडल क्या है?
  49. RDBMS Applications in Hindi
  50. MySQL क्या है?
  51. Parallel Database in Hindi
  52. Database Costs and Risk Factors in Hindi
  53. डिस्ट्रिब्यूटेड डेटाबेस क्या होता है?
  54. Operational Data vs Decision Support Data in Hindi
  55. फाइल ओरिएंटेड सिस्टम के लाभ और हानियाँ
  56. DBMS में Mapping Constraints क्या होते हैं?
  57. DBMS vs File System in Hindi
  58. Validation Based Protocol in Hindi
  59. Multivalued Dependency in DBMS in Hindi & Join Dependency in Hindi
  60. Relationship Set in DBMS in Hindi
 

निष्कर्ष (Conclusion)

PL/SQL Exception Handling सुनिश्चित करता है कि:

  1. प्रोग्राम अचानक बंद न हो
  2. User को meaningful message मिले
  3. Data सुरक्षित रहे
  4. Debugging आसान हो जाए

इसलिए, किसी भी professional PL/SQL programming में exception handling का इस्तेमाल जरूरी होता है।

Leave a Comment