Total Page Preview:   000000000259

What is Exception Handling in C-Sharp in English and Hindi




Exception Handling in C-Sharp in English:

Exception handling in C# is a mechanism that allows developers to gracefully handle errors or exceptional conditions that may occur during the execution of a program. By using exception handling, developers can write more robust and reliable code that can recover from errors and continue running.

In C#, exceptions are represented by objects that derive from the System.Exception class. When an exceptional condition occurs, an exception object is created and thrown. The thrown exception is propagated up the call stack until it is caught by an exception handler.
Here is an example of exception handling in C#:
In this example, an array of integers is created with a length of 5. However, the code attempts to access the 11th element of the array (which does not exist), resulting in an IndexOutOfRangeException being thrown. The exception is caught by a catch block that prints an error message to the console.
The finally block is used to specify code that should be executed regardless of whether an exception was thrown or not. In this case, the finally block prints a message to the console indicating that it was executed.
Using exception handling in C# can help make your code more robust and reliable by providing a way to gracefully recover from errors and continue running.
Exception Handling in C-Sharp in Hindi:
Exception Handling C# mai ek mechanism hai jo developers ko program ki execution k dauraan aane waale errors ya exceptional conditions ko gracefully handle karne ki ijazat deta hai. Exception handling ka istemaal karke, developers zyada robust aur reliable code likh sakte hain jisse errors ko recover kiya ja sakta hai aur program chalta rehta hai.
C# mai, exceptions System.Exception class se derived objects se represent kiye jaate hain. Jab exceptional condition hoti hai, ek exception object create kiya jaata hai aur usko throw kiya jaata hai. Thrown exception call stack tak propagate hoti hai jab tak ki kisi exception handler se catch nahi kiya jaata hai.
Neeche ek C# mai exception handling ka example diya gaya hai:
Is example mein, ek integer array 5 length ke saath create kiya gaya hai. Par code mein 11th element ko access karne ki koshish ki gayi hai (jo exist nahi karta), jiski wajah se IndexOutOfRangeException throw kiya gaya hai. Exception ko ek catch block dwara catch kiya gaya hai jo console mein ek error message print karta hai.
finally block ka upyog isliye kiya gaya hai ki use specify karne ke liye ki kaun sa code execute hona chahiye, chahe exception throw hua ho ya na ho. Is case mein, finally block ek message ko console mein print karta hai jo indicate karta hai ki yeh execute kiya gaya hai.
C# mein exception handling ka upyog karne se aapka code errors se recover karne wala aur reliable ban sakta hai, kyunki exception handling ek tareeka pradaan karta hai errors ko gracefully recover karne ka aur code ko continue karne ka.

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn :





Facebook User: