Book Image

Learn C# in 7 days

By : Gaurav Aroraa
1 (1)
Book Image

Learn C# in 7 days

1 (1)
By: Gaurav Aroraa

Overview of this book

This book takes a unique approach to teach C# to absolute beginners. You’ll learn the basics of the language in seven days. It takes a practical approach to explain the important concepts that build the foundation of the C# programming language. The book begins by teaching you the basic fundamentals using real-world practical examples and gets you acquainted with C# programming. We cover some important features and nuances of the language in a hands-on way, helping you grasp the concepts in a fluid manner. Later, you’ll explore the concepts of Object-Oriented Programming (OOP) through a real-world example. Then we dive into advanced-level concepts such as generics and collections, and you’ll get acquainted with objects and LINQ. Towards the end, you’ll build an application that covers all the concepts explained in the book. By the end of this book, you will have next-level skills and a good knowledge of the fundamentals of C#.
Table of Contents (15 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Exception handling


Exception is a kind of error that comes when methods do not work as expected or are not able to handle the situation as intended. Sometimes, there might be unknown situations where exceptions occurred; for instance, a method can have a situation divide by zero problem in division operation the situation was never expected while someone wrote the method, this is an unpredicted situational error. To handle these kind of situations and other unknown scenarios that can create such exceptions or error, C# provides a method that is called exception handling. In this section, we will discuss exceptions and exception handing using C# in details.

Note

Exceptions can be handled using the try...catch...finally block. Catch or finally blocks should be there with the try block to handle exceptions.

Consider the following code:

class ExceptionhandlingExample
    {
        public int Div(int dividend,int divisor)
        {
            //thrown an exception if divisor is 0
            return...