Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • C# - Get Started
  • C# - Version History
  • C# - First Program
  • C# - Keywords
  • C# - Class and Objects
  • C# - Namespace
  • C# - Variables
  • C# - Implicitly-Typed Variables
  • C# - Data Types
  • Numbers
  • Strings
  • DateTime
  • Structure
  • Enum
  • StringBuilder
  • Anonymous Types
  • Dynamic Types
  • Nullable Types
  • C# - Value & Reference Types
  • C# - Interface
  • C# - Operators
  • C# - if else Statements
  • C# - Ternary Operator ?:
  • C# - Switch
  • C# - For Loop
  • C# - While Loop
  • C# - Do-while Loop
  • C# - Partial Class
  • C# - Static
  • C# - Array
  • Multidimensional Array
  • Jagged Array
  • C# - Indexer
  • C# - Generics
  • Generic Constraints
  • C# - Collections
  • ArrayList
  • List
  • SortedList
  • Dictionary
  • Hashtable
  • Stack
  • Queue
  • C# - Tuple
  • C# - ValueTuple
  • C# - Built-in Exceptions
  • Exception Handling
  • throw
  • Custom Exception
  • C# - Delegates
  • Func Delegate
  • Action Delegate
  • Predicate Delegate
  • Anonymous Methods
  • C# - Events
  • C# - Covariance
  • C# - Extension Method
  • C# - Stream I/O
  • C# - File
  • C# - FileInfo
  • C# - Object Initializer
  • OOP - Overview
  • Object-Oriented Programming
  • Abstraction
  • Encapsulation
  • Association & Composition
  • Inheritance
  • Polymorphism
  • Method Overriding
  • Method Hiding
  • C# - Solid Principles
  • Single Responsibility Principle
  • Open/Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle
  • Design Patterns
  • Singleton
  • Abstract Factory
  • Factory Method
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

Built-in Exception Classes in C#

Here you will learn about the built-in exception classes in C#.

C# .NET includes built-in exception classes for every possible error. The Exception class is the base class of all the exception classes.

The following is a hierarchy of exception classes in .NET:

Exception Classes in .NET

In the above figure, the Exception class is the base class of the SystemException and ApplicationException classes. The SystemException class is the base class for all the built-in exception classes in .NET Framework.

The ApplicationException was recommended to be base class for all your custom exceptions classes (The custom exeception class should be created if non of the system exception classes can be used and you need new exception class for business rule violations or for other application related errors). It was meant to differentiates between exceptions defined by applications versus exceptions defined by the system. However, Microsoft now recommends to derive custom exception classes from the Exception class rather than the ApplicationException class .

The following figure shows how the NullReferenceException is thrown in Visual Studio debug mode when you access a null object property at runtime.

NullReferenceException

Built-in Exception Classes

The following table lists important built-in exception classes in .NET.

Exception Class Description
ArgumentExceptionRaised when a non-null argument that is passed to a method is invalid.
ArgumentNullExceptionRaised when null argument is passed to a method.
ArgumentOutOfRangeExceptionRaised when the value of an argument is outside the range of valid values.
DivideByZeroExceptionRaised when an integer value is divide by zero.
FileNotFoundExceptionRaised when a physical file does not exist at the specified location.
FormatExceptionRaised when a value is not in an appropriate format to be converted from a string by a conversion method such as Parse.
IndexOutOfRangeExceptionRaised when an array index is outside the lower or upper bounds of an array or collection.
InvalidOperationExceptionRaised when a method call is invalid in an object's current state.
KeyNotFoundExceptionRaised when the specified key for accessing a member in a collection is not exists.
NotSupportedExceptionRaised when a method or operation is not supported.
NullReferenceExceptionRaised when program access members of null object.
OverflowExceptionRaised when an arithmetic, casting, or conversion operation results in an overflow.
OutOfMemoryExceptionRaised when a program does not get enough memory to execute the code.
StackOverflowExceptionRaised when a stack in memory overflows.
TimeoutExceptionThe time interval allotted to an operation has expired.

When an error occurs, either the application code or the default handler handles the exception. Learn how to handle the excetion in the next section.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.