Issue 22025 - Exception within a delegate can't be thrown.
Summary: Exception within a delegate can't be thrown.
Status: RESOLVED DUPLICATE of issue 21919
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P1 critical
Assignee: No Owner
URL:
Keywords: backend
Depends on:
Blocks:
 
Reported: 2021-06-15 09:53 UTC by Heromyth
Modified: 2021-11-22 14:14 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Heromyth 2021-06-15 09:53:03 UTC
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
```
Comment 1 Mathias LANG 2021-06-16 05:23:20 UTC
Reproduced.

```
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1003c7c00)
  * frame #0: 0x00007fff2032f50c libsystem_pthread.dylib`___chkstk_darwin + 96
    frame #1: 0x00007fff2032f4ac libsystem_pthread.dylib`thread_start + 20
    frame #2: 0x00007fff2a4adb2d libunwind.dylib`libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_x86_64>::getInfoFromDwarfSection(unsigned long, libunwind::UnwindInfoSections const&, unsigned int) + 191
    frame #3: 0x00007fff2a4ada01 libunwind.dylib`libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_x86_64>::setInfoBasedOnIPRegister(bool) + 999
    frame #4: 0x00007fff2a4afec9 libunwind.dylib`libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_x86_64>::step() + 461
    frame #5: 0x00007fff2a4b1a18 libunwind.dylib`_Unwind_RaiseException + 189
    frame #6: 0x000000010005c0fd future`_d_throwdwarf + 185
    frame #7: 0x0000000100001e9d future`_D4mainQfFZ9__lambda3MFNaNfiZi(__capture=0x0000000100600000, x=30) at object.d:2478
    frame #8: 0x0000000100025aea future`_D7toolkit7promise__T9asyncImplTDFNaNfiZiTiZQxFQpiZ9__lambda6MFZv(__capture=0x0000000100604030) at promise.d:446
    frame #9: 0x0000000100058d79 future`_D4core6thread7context8Callable6opCallMFZv + 41
    frame #10: 0x0000000100055227 future`fiber_entryPoint + 99
```

I've been seeing this issue for a while: https://github.com/dlang/dub/issues/2120
Comment 2 Mathias LANG 2021-06-16 05:24:39 UTC
Note that this is yet another DMD-specific bug, compiling with LDC works.
Comment 3 Iain Buclaw 2021-07-23 19:54:10 UTC
Probably a duplicate of issue 21919
Comment 4 Iain Buclaw 2021-11-07 23:40:07 UTC
PR submitted, please check this again.

https://github.com/dlang/druntime/pull/3612
Comment 5 Iain Buclaw 2021-11-22 14:14:15 UTC
Library issue, not compiler.

Tested on 11.6, and output of result is the same as Linux, so this is a indeed a duplicate.

*** This issue has been marked as a duplicate of issue 21919 ***