System.Exception.Message

Summary

Gets an error message that describes the current exception.

Syntax
public override string Message { get; }
Property Value

System.String A string that describes the error.

Remarks

The Message property is automatically initialized to a system-supplied message that describes the error. If the exception is thrown as a result of a method call, the error message may reflect the argument that caused the exception. This message can be displayed to the end user to help them diagnose the problem.

The Message property can be overridden in derived classes to return a custom error message.

Example

The following example demonstrates how to catch an exception and display its message.

try { // Code that might throw an exception throw new ArgumentException("Invalid argument provided."); } catch (Exception ex) { // Display the exception message to the user Console.WriteLine("An error occurred: " + ex.Message); }
See Also
Reference Description
Exception Class Represents errors that occur during application execution.
String Class Represents text as a sequence of characters.