d-bugm...@puremagic.com wrote:

           Summary: Allow exception in CTFE (patch)
           Product: D
           Version: 2.030
          Platform: x86
        OS/Version: All
            Status: NEW
          Keywords: patch
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzi...@digitalmars.com
        ReportedBy: rsi...@gmail.com

Created an attachment (id=389)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=389)
Patch (DMD 2.030)

The proposed patch implements support for throw/try/catch/finally in CTFE.
Throw statement is, however, somewhat limited; new expression is not allowed,
except for new Exception("msg").

Example and output:
int thrower(string s)
    // The interpretor emulates throw new Exception("msg")
    throw new Exception("exception " ~ s);
    return 0;

int catcher()
        return thrower("abc");
    catch (Exception e)
        throw e;
    return 0;

enum a = catcher("abc");
test.d(21): Error: uncaught exception from catcher(): "exception abc"
test.d(21): Error: cannot evaluate catcher() at compile time

Since scope() is defined in terms of try/finally, would it be much harder to get scope(success/failure/exit) working in CTFE?

Reply via email to