Throwing custom errors in hindi

Throwing custom errors In Hindi

जावास्क्रिप्ट प्रोग्रामिंग में प्रोग्रामर किसी प्रोग्राम में एरर हैंडलिंग को अपने सॉफ्टवेयर डेवलपमेंट नीड के अनुसार प्रोग्राम में कस्टम एरर क्रिएट कर उसे थ्रो कर सकते हैं। जावास्क्रिप्ट प्रोग्राम में कस्टम एरर को अप्लाई करके प्रोग्रामर प्रोग्राम में कस्टम एरर क्रिएट कर मल्टीप्ल प्रोग्राम में सोर्स रेफ़्रेन्स को ऐड कर सकते हैं. जैसे, कस्टम एरर मैसेज क्रिएट करना, प्रोग्राम में एरर कोड, या नई  प्रॉपर्टीज़ को डिस्प्ले करना, आदि है. जो की प्रोग्रामर को किसी प्रोग्राम में एरर को डीबग करना और प्रॉपर आर्डर में प्रोग्राम एरर सिचुएशन को कण्ट्रोल और मैनेज करना आसान हो जाता है।

Throwing custom errors in hindi

Syntax of Error Throw in JavaScript.

जावास्क्रिप्ट प्रोग्राम में थ्रो स्टेटमेंट का उपयोग किसी प्रोग्राम में कस्टम एक्सेप्शन को थ्रो करने में किया जाता है। जावास्क्रिप्ट प्रोग्रामर Error, TypeError, या RangeError जैसी बिल्ट-इन कस्टम एरर क्रिएट कर उसे प्रोग्राम में थ्रो कर सकते हैं, इसके अलावा प्रोग्रामर जरूरत के अनुसार  कस्टम एरर क्लास को क्रिएट कर सकते हैं।

throw new Error(“display custom throw statement”);

Creating a custom error in JavaScript.

जावास्क्रिप्ट प्रोग्रामिंग में कस्टम एरर क्रिएट करने के लिए प्रोग्रामर बिल्ट-इन Error क्लास को अप्लाई कर उसे एक्सटेंड कर सकते हैं। जहा जावास्क्रिप्ट प्रोग्रामर इंडिविजुअल एरर क्लास क्रिएट कर प्रोग्रामर उसमे कस्टम एरर में नई प्रॉपर्टीज़ या मेथड्स को अप्लाई कर सकते हैं. जो किसी प्रोग्राम में एरर के बारे में डिटेल्ड इनफार्मेशन को प्रोवाइड करते हैं।

A new custom error class example in JavaScript.

class manualError extends Error {

    constructor(errormessage, error_Code) {

        super(errormessage);  // here it Call the parent class constructor object

        this.error_name = this.constructor.error_name;  // we can Set the name of the error to the class name

        this.error_Code = error_Code;  // let we Add a custom error code property here

    }

}

throw new manualError(“invalid value input”, 200);

Explanation of Creating a custom error.

यहाँ मौजूदा प्रोग्राम में manualError, Error कस्टम क्लास को एक्सटेंड करता है।

errormessage और error_Code कंस्ट्रक्टर वैल्यू को पास करता हैं।

यहाँ super(message) कॉल मेथड एरर मैसेज को स्टार्ट करने के लिए पैरेंट क्लास (Error) कंस्ट्रक्टर को इनवोक करेगा।

this.error_name = this.constructor.error_name एरर के नाम को क्लास के नाम पर डिफाइन करता है, यहाँ इस कंडीशन में manualError है।

जहा प्रोग्राम में error_Code एक कस्टम प्रॉपर्टी मेथड है, जिसका उपयोग प्रोग्रामर एक स्पेशल एरर टाइप को डिफाइन करने के लिए कर सकते हैं।

Use of custom error class in JavaScript program.

जावास्क्रिप्ट प्रोग्रामर अपने एप्लीकेशन डेवलपमेंट जरूरत के अनुसार एक कस्टम एरर क्लास को डिफाइन करने के बाद प्रोग्रामर इसमें किसी भी अन्य प्रकार की एरर मैसेज को थ्रो कर सकते हैं। जहा catch ब्लॉक मेथड में किसी कस्टम एरर को कैच कर उसे कण्ट्रोल और मैनेज कर सकते हैं।

Example of throw and catch block method to throw custom error in JavaScript program.

class manualError extends Error {

    constructor(errormessage, error_Code) {

        super(errormessage);

        this.errorname = this.constructor.errorname;

        this.error_Code = error_Code;

    }

}

function testvalue(test) {

    if (!test) {

        throw new manualError(“Enter test data”, 200);  // it used to Throw custom error if testvalue is missing

    }

    console.log(“enter Data done successfully”);

}

try {

    testvalue(null);  // here it used to throw a CustomError

} catch (error) {

    if (error instanceof manualError) {

        console.log(“it caught custom error -“, error.message);

        console.log(“Display Error Code -“, error.error_Code);

    } else {

        console.log(“May be unexpected error generate -“, error);

    }

}

Explanation of custom error class.

यहाँ इस प्रोग्राम में यदि डेटा एंटर नहीं किया जाता है, तो testvalue() फ़ंक्शन एक manualError को थ्रो करता है।

यहाँ catch ब्लॉक मेथड यह चेक करता है कि क्या मौजूदा प्रोग्राम में एरर manualError का एक उदाहरण है, यह एक्टिव प्रोग्राम में एक कस्टम मैसेज और एरर कोड को डिस्प्ले करता है।

Handling custom errors with additional properties in JavaScript.

जावास्क्रिप्ट प्रोग्राम में इंडिविजुअल कस्टम एरर में कोई भी अन्य प्रॉपर्टीज को ऐड कर सकते हैं. जैसे, प्रोग्राम में टाइमस्टैम्प, स्टेट, या कोई अन्य जानकारी है, जो प्रोग्रामर को मौजूदा प्रोग्राम में एरर को प्रॉपर आर्डर में अंडरस्टैंड करने या मैनेज करने में हेल्प करते है।

Example of additional properties in JavaScript programming.

class dbError extends Error {

    constructor(errormessage, query, errorCode) {

        super(errormessage);

        this.dbname = this.constructor.dbname;

        this.query = query;  // it used to Store the database query which caused the error

        this.errorCode = errorCode;  // let create here Custom error code

        this.timestamp = new Date();  // let Add a timestamp of when the error occurred in database

    }

}

function launchQuery(query) {

    if (query === “”) {

        throw new dbError(“Query should not be empty”, query, 200);

    }

    console.log(“required Query run successfully”);

}

try {

    launchQuery(“”);  // let create a multiple tray and catch method that will throw a DatabaseError

} catch (error) {

    if (error instanceof dbError) {

        console.log(“Display Database Error -“);

        console.log(“Display error Message -“, error.message);

        console.log(“Display database Query -“, error.query);

        console.log(“Display Error Code -“, error.errorCode);

        console.log(“Display Timestamp -“, error.timestamp);

    } else {

        console.log(“Produce any Unexpected error -“, error);

    }

}

Explanation of additional properties in JavaScript.

इस प्रोग्राम में dbError क्लास एक डेटाबेस Error क्लास को एक्सटेंड कर रहा है, और डेटाबेस क्वेश्चन क्वेरी के लिए errorCode, और timestamp जैसे प्रॉपर्टीज़ को ऐड करता है।

यहाँ launchQuery() फ़ंक्शन में, यदि क्वेरी एक खाली स्ट्रिंग होती है, तो एक DatabaseError डिस्प्ले होगा।

यहाँ catch ब्लॉक मेथड मौजूदा प्रोग्राम में DatabaseError को मैनेज और हैंडल करता है, और कस्टम प्रॉपर्टीज़ को डिस्प्ले करता है।

Summary of error handling and custom error throwing.

  • Throwing errors in a program – जावास्क्रिप्ट प्रोग्रामर जावास्क्रिप्ट प्रोग्राम में थ्रो कीवर्ड को अप्लाई करके कस्टम एरर को थ्रो कर सकते हैं, जहा ये कस्टम एरर बिल्ट-इन Error क्लास के एक्साम्प्ल या Error को एक्सटेंड करने वाली कस्टम क्लासेज हो सकती हैं।
  • Creating a custom error class – यहाँ प्रोग्रामर कस्टम इंडिविजुअल एरर क्लास जैसे, manualError क्रिएट कर प्रोग्रामर एरर कोड, टाइमस्टैम्प या रेफ़्रेन्स-स्पेसिफिक डिस्क्रिप्शन जैसे कस्टम प्रॉपर्टीज को ऐड कर सकते हैं।
  • Catching custom errors in the program – यहाँ मौजूदा प्रोग्राम में प्रोग्रामर कई कस्टम एरर को कैच कर सकते हैं, और एरर टाइप की टेस्टिंग कर करने के लिए instanceof मेथड को अप्लाई करके उन्हें कैच ब्लॉक मेथड में हैंडल कर सकते हैं।
  • Best practice of custom errors and throws keyword – यहाँ Error क्लास को एक्सटेंड करें, super(message) पैरेंट मेथड का उपयोग करें, और अपनी कस्टम एरर को अधिक हेल्पफुल और हेंडल करने में आसान बनाने के लिए अतरिक्त क्लास प्रॉपर्टीज को ऐड करे।

Leave a Reply