[Issue 3050] New: Allow exception in CTFE (patch)

Robert Fraser fraserofthenight at gmail.com
Thu Jun 4 16:04:58 PDT 2009


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=3050
> 
>            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: bugzilla at digitalmars.com
>         ReportedBy: rsinfu at 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()
> {
>     try
>     {
>         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?


More information about the Digitalmars-d-bugs mailing list