www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22025] New: Exception within a delegate can't be thrown.

https://issues.dlang.org/show_bug.cgi?id=22025

          Issue ID: 22025
           Summary: Exception within a delegate can't be thrown.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bitworld qq.com

When throwing an exception within a delegate, the app crashed.

My OS is macOS Big Sur 11.4. It's OK in Linux.

Tested compilers: DMD 2.088.1 - 2.097.0

Here is the sample:

```
void main() {
    int factor = 2;
    auto ex2a = new Promise!int();

    auto ex2b = ex2a.then!(async!((int x) { 
            if(x == 30) {
                // It's a bug in macOS Big Sur 11.4
                throw new Exception("throw an exception!");
            }
            return x * factor; 
        }));    

    ex2a.resolve(30); // throw an exception!
}
```

The steps are here for reproducing this bug:

```
$ git clone https://github.com/Heromyth/future.git
$ cd future
$ dub run
```

--
Jun 15