Comment #0 by destructionator — 2020-11-22T18:46:13Z
---
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)
Comment #1 by destructionator — 2020-11-22T20:25:53Z
this might be a druntime bug instead of dmd. but i suspect it is both due to too many void* in the interface layer.
Comment #2 by kozzi11 — 2020-11-23T17:42:07Z
I would say this one is even worse:
immutable foo = new Exception("omg");
void main() {
import std.stdio;
try {
throw foo;
} catch(Exception e) {
e.msg = "broken";
writeln("caught ", e);
}
}
Comment #3 by destructionator — 2020-11-23T17:48:20Z
Yeah, the immutability being lost destroyed what I was hoping to do with this, so definitely the bigger problem. But it being lost either direction is problematic.
Really a "catch-all" would be `catch(const Throwable)`. Const and immutable objects should NOT be caught by a catch mutable. I realize nobody thinks about this but we probably should start.
An immutable exception can be used without allocation concerns.