[Issue 21415] New: catch immutable exceptions breaks immutable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 22 18:46:13 UTC 2020


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

          Issue ID: 21415
           Summary: catch immutable exceptions breaks immutable
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: destructionator at gmail.com

---
immutable foo = new Exception("omg");

void main() {
        import std.stdio;
        try {
                //throw foo;
                throw new Exception("wtf");
        } catch(immutable Exception e) {
                //e.msg = "broken";
                writeln("caught ", e);
        }
}
---

In that example, it silently casts the mutable Exception to immutable.

If you throw foo and catch Exception, it silently casts the immutable Exception
to mutable. So the mutability stuff is lost here.

(I was exploring throwing immutable static exceptions as a possibility for
nogc)

--


More information about the Digitalmars-d-bugs mailing list