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
- ApplicationException
- Attribute
- BadImageFormatException
- CannotUnloadAppDomainException
- CharUnicodeInfo
- CLSCompliantAttribute
- Console
- Convert
- DataMisalignedException
- DivideByZeroException
- DllNotFoundException
- DuplicateWaitObjectException
- EntryPointNotFoundException
- Enum
- ExecutionEngineException
- FieldAccessException
- FormatException
- GenericTypeArgumentException
- IndexOutOfRangeException
- InsufficientExecutionStackException
- InvalidCastException
- InvalidComObjectException
- InvalidFilterStackException
- InvalidHandleCountException
- InvalidProgramException
- InvalidOperationException
- InvalidTimeZoneException
- IOSErrorException
- IOException
- IrrelevantOverlappedException
- LinkedResource
- LoaderOptimization
- MemberAccessException
- MethodAccessException
- MissingFieldException
- MissingMemberException
- MissingMethodException
- MulticastDelegate
- NotFiniteNumberException
- NotImplementedException
- NullReferenceException
- Object
- OutOfMemoryException
- OverflowException
- PlatformNotSupportedException
- RankException
- RemotingException
- SafeHandle
- SerializationException
- StackOverflowException
- SystemException
- ThreadStaticAttribute
- TimeZoneInfo
- TypeAccessException
- TypeLoadException
- TypeUnloadedException
- UnauthorizedAccessException
- UnhandledExceptionEventArgs
- Uri
- UriBuilder
- UriFormatException
- Version
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}"); }