raise

Function used to signal a failure and its proximate cause from integer math code. Depending on the value of the policy parameter, raise() will either:

  • Throw a CheckedIntException,
  • Trigger an assertion failure, or
  • Set a bit in IntFlags.local that can be checked by the caller later.
  1. void raise(IntFlags flags)
    template raise(IntFlagPolicy policy)
    @safe pure
    static if(policy == IntFlagPolicy.throws)
    void
    raise
  2. void raise(IntFlag flag)
  3. void raise(IntFlags flags)
  4. void raise(IntFlag flag)
  5. void raise(IntFlags flags)
  6. void raise(IntFlag flag)
  7. void raise(IntFlags flags)
  8. void raise(IntFlag flag)

Members

Functions

raise
void raise(IntFlags flags)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlag flag)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlags flags)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlag flag)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlags flags)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlag flag)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlags flags)
Undocumented in source. Be warned that the author may not have intended to support it.
raise
void raise(IntFlag flag)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

import checkedint.throws : raise; // set IntFlagPolicy.throws

bool caught = false;
try
{
    raise(IntFlag.div0);
}
catch(CheckedIntException e)
{
    caught = (e.intFlags == IntFlag.div0);
}
assert(caught);
import checkedint.asserts : raise; // set IntFlagPolicy.asserts

bool caught = false;
try
{
    raise(IntFlag.div0);
}
catch(Error e)
{
    caught = (e.msg == "divide by zero");
}
assert(caught);
import checkedint.noex : raise; // set IntFlagPolicy.noex

raise(IntFlag.div0);
raise(IntFlag.posOver);

assert(IntFlags.local.clear() == (IntFlag.div0 | IntFlag.posOver));
// Multiple signaling strategies may be usefully mixed within the same program:
alias IFP = IntFlagPolicy;

static void fails() nothrow
{
    raise!(IFP.noex)(IntFlag.negOver);
    raise!(IFP.noex)(IntFlag.imag);
}

bool caught = false;
try
{
    fails();
    // Flags that were raised by `nothrow` code can easily be turned into an exception by the caller.
    raise!(IFP.throws)(IntFlags.local.clear());
}
catch(CheckedIntException e)
{
    caught = (e.intFlags == (IntFlag.negOver | IntFlag.imag));
}
assert(caught);

Meta