MailMessageThrowExceptions Property
Gets or sets whether the MailMessage object will throw exceptions on errors.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public bool ThrowExceptions { get; set; }

Property Value

Type: Boolean
true if MailMessage object will throw exceptions on errors; otherwise, false. The default value is true.

If this property is set to true and an error occurs, an exception derived from MailBeeException is thrown.

Note Note
The code of the last occurred error is always contained in LastResult property. The list of all error codes is available in ErrorCodes class overview.

Even if this property is set to false, the exceptions which occur due to errors in MailBee usage will still be thrown. Typical example of such errors is passing invalid arguments to methods.

This sample simulates an error and exception by attempting to load a file with non-existent name. The first attempt is made with exceptions turned off, the second - with exceptions turned on.
using System;
using MailBee;
using MailBee.Mime;

class Sample
    static void Main(string[] args)
        MailMessage msg = new MailMessage();

        // Turn off exception handling.
        msg.ThrowExceptions = false;

        // Generate an error.
        if (!msg.LoadMessage("Wrong Path"))
            Console.WriteLine("Error occurred. Error code is " + msg.LastResult.ToString());

        // Turn on exception handling.
        msg.ThrowExceptions = true;

        // The code below will throw an exception.
            msg.LoadMessage("Wrong Path");
        catch (MailBeeException ex)
            // But we catch it. We display the type of the exception. In your app,
            // you can check other useful properties such as Message or ErrorCode.
            Console.WriteLine("\r\nThe following exception was thrown:\r\n" + ex.GetType().ToString());
See Also