www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23061] New: Exceptions cannot be caught by catch statement in

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

          Issue ID: 23061
           Summary: Exceptions cannot be caught by catch statement in
                    static build
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: ttanjo gmail.com

Exceptions cannot be caught in the static linked configuration but they should
be caught.
In the dynamic linked configuration, they can be caught as intended.

I first filed it in ldc but finally I found it is a issue in druntime.
- https://github.com/ldc-developers/ldc/issues/3965


I checked this issue with the following environment with Docker container.
- dmd 2.098.0-r0 in Alpine Linux 3.15
- ldc 1.28.0-r0 in Alpine Linux 3.15
- ldc 1.28.1-r0 in Alpine Linux edge



app.d:

```dlang
void main(string[] args)
{
        try
        {
                throw new Exception("aaa");
        }
        catch(Exception e)
        {
        }
}
```

Compile and execute it in Alpine Linux image as follows:

```console
$ docker run --rm -it -v $PWD:/workdir -w /workdir alpine:3.15 sh




/lib/ld-musl-x86_64.so.1: app: Not a valid dynamic program

```


It can be executed without errors.


It fails execution with the exception message.

```console

src/rt/dwarfeh.d:330: uncaught exception reached top of stack
This might happen if you're missing a top level catch in your fiber or signal
handler
object.Exception app.d(11): aaa
----------------
??:? <ERROR: Unable to retrieve function name> [0x0]
Aborted
```

Note that it can successfully be executed when I compile it with `dmd app.d`.

---
I reproduce the same issue with ldc as the following instructions:

```console
$ docker run --rm -it -v $PWD:/workdir -w /workdir alpine:3.15 sh



rt/dwarfeh.d:354: uncaught exception reached top of stack
This might happen if you're missing a top level catch in your fiber or signal
handler
object.Exception app.d(11): aaa
----------------
src/ctype/isspace.c:10 <ERROR: Unable to retrieve function name> [0x0]
Aborted
```

--
Apr 26 2022