System.Runtime Namespace

Contains fundamental types and base classes that define characteristics of the common language runtime (CLR) and fundamental data types. This namespace includes types that are used for various runtime operations, such as memory management, exception handling, and threading.

Classes

Interfaces

Enumerations

Delegates

Sample Usage: Handling Exceptions

Catching a NullReferenceException

Demonstrates how to gracefully handle a common runtime exception.

try
{
    object obj = null;
    Console.WriteLine(obj.ToString()); // This will throw NullReferenceException
}
catch (NullReferenceException ex)
{
    Console.WriteLine("An error occurred: A null reference was encountered.");
    Console.WriteLine($"Details: {ex.Message}");
    Console.WriteLine($"Stack Trace: {ex.StackTrace}");
}
catch (Exception ex) // Catch any other unexpected exceptions
{
    Console.WriteLine($"An unexpected error occurred: {ex.Message}");
}