find and solve || findandsolve.com
Please wait.....

C# SystemException class

The SystemException is a predefined exception class in C# programming language and used to handle system related exceptions. C# provides a predefined exception class to handle the system-related exceptions.

It has various child classes like:  ArgumentException, ValidationException, DataException,  ArithmeticException, StackOverflowException etc.

C# SystemException Signature

[SerializableAttribute]  
[ComVisibleAttribute(true)]
public class SystemException : Exception  


C# SystemException Constructors

ConstructorsDescription
SystemException() This is used to initialize a new instance of the SystemException class
SystemException(SerializationInfo,StreamingContext)This is used to initialize a new instance of the SystemException class with serialized data.
SystemException(String) This is used to initialize a new instance of the SystemException class with a specified error message.
SystemException(String,Exception) This is used to initialize a new instance of the SystemException class with a specified error message and a reference to the inner exception that is the cause of this exception.


C# SystemException Properties

PropertyDescription
DataTo used to get a collection of key/value pairs that provide additional user-defined information about the exception.
HelpLinkTo used to get or set a link to the help file associated with this exception.
HResultTo  used to get or set HRESULT, a coded numerical value that is assigned to a specific exception.
InnerExceptionTo used to get the Exception instance that caused the current exception.
MessageTo used to get a message that describes the current exception.
SourceTo used to get or set the name of the application that causes the error.
StackTraceTo used to get a string representation of the immediate frames on the call stack.
TargetSiteTo  used to get the method that throws the current exception.

C# SystemException Methods

MethodDescription
Equals(Object)  To verify whether the specified object is equal to the current object or not.
Finalize()  To free the resources and to perform cleanup operations.
GetBaseException() To return the root exception.
GetHashCode() To return the hash code.
GetObjectData(SerializationInfo,StreamingContext)To used to get object data.
GetType() To used to get the runtime type of the current instance.
MemberwiseClone() To used to create a shallow copy of the current Object.
ToString() To used to create and return a string representation of the current exception.


C# SystemException Example

using System;  
namespace FindAndSolve
{
    public class Program
    {
        public static void Main(string[] args)
        {
           try
            {
                int[] arr = new int[4];
                arr[8] = 20;
            }
            catch (SystemException e)
            {
                Console.WriteLine(e);
            }
        }
    }
}

Output

System.IndexOutOfRangeException: Index was outside the bounds of the array.

   at FindAndSolve.Program.Main(String[] args) in d:\Windows\Temp\mdzsamrv.0.cs:line 11