Problem with Exceptions in Constructor
Mike Brown
mikey.be at gmail.com
Fri Jun 11 20:09:22 UTC 2021
Hi all,
AddressSanitizer is throwing an access-violation error - I've
managed to boil it down to this example:
```d
import std.stdio;
class example: Exception {
this(string msg, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line);
}
}
class test {
this() {
throw new example("this is a test");
}
}
void main() {
try {
auto t = new test();
} catch (example e) {
writeln(e.msg);
}
}
```
Compiled with:
ldc2.exe -g -fsanitize='address' .\test.d -of='test.exe'
The error is flagged on the writeln(e.msg). Do I need to do
something special to pass a string to an exception? dup?
Kind regards,
Mike Brown
More information about the Digitalmars-d-learn
mailing list