Exceptions

Exceptions are variants and records that describe errors. Use exception keyword instead of record to define an exception record:

Example:

exception NeedMoreMinerals
{
    int amount;
}

To define exception variant, use exception variant keywords:

Example:

enum ExceptionType
{
    name_exists;
    private_message_delivery_failed;
}

exception variant ChatException
{
    tag ExceptionType type;
}

exception ChatException.NameExistsException[name_exists]
{
    string name;
}

exception ChatException.PrivateMessageDeliveryFailedException[private_message_delivery_failed]
{
    string name;
}

While exceptions may be used as regular records, there’s a number of differences:

  • Generic exceptions are not supported at the moment

  • Target language generators may have special rules for exceptions. For example in C# exceptions have to be derived from System.Exception class.

  • Exceptions are used in services to throw errors. See Services for details.