Share via


IManagementUIService.ShowError(Exception, String, String, Boolean) Method

Definition

Displays the specified exception and information about the exception in a message box.

public:
 void ShowError(Exception ^ exception, System::String ^ message, System::String ^ caption, bool isWarning);
public void ShowError (Exception exception, string message, string caption, bool isWarning);
abstract member ShowError : Exception * string * string * bool -> unit

Parameters

exception
Exception

The Exception to display.

message
String

A message to display that provides information about the exception.

caption
String

The caption for the message box.

isWarning
Boolean

true if the error message is to be considered a warning; otherwise, false.

Examples

The following example implements this method.

private IWin32Window DialogOwner {
    get {
        return _curWin.Peek();
    }
} 
void IManagementUIService.ShowError(
    Exception exception, 
    string message,
    string caption,
    bool isWarning) {

    string text = message;

    if (exception != null) {
        if (!String.IsNullOrEmpty(text)) {
            text += Environment.NewLine + Environment.NewLine;
        }
        text += exception.Message;
    }

    MessageBoxIcon icon = isWarning ? MessageBoxIcon.Warning : MessageBoxIcon.Error;

    ShowMessage(DialogOwner,
        _owner.Title,         // member var init in MyUI_Srvc ctor
        caption,
        text,
        icon,                // Warning | Error
        MessageBoxButtons.OK,
        MessageBoxDefaultButton.Button1);
} 
internal DialogResult ShowMessage(
    IWin32Window owner,
    string appTitle,
    string caption, string text,
    MessageBoxIcon icon,
    MessageBoxButtons buttons,
    MessageBoxDefaultButton defaultButton) {

    if (String.IsNullOrEmpty(caption)) {
        caption = appTitle;
    }

    MessageBoxOptions options = (MessageBoxOptions)0;

    if ((owner is Control && owner != null &&
        ((Control)owner).RightToLeft == RightToLeft.Yes) ||
        _rightToLeft) {
        options |= MessageBoxOptions.RtlReading |
            MessageBoxOptions.RightAlign;
    }

    return MessageBox.Show(owner, text, caption,
        buttons, icon, defaultButton, options);
} 

Applies to