On Wednesday, 17 March 2021 at 17:52:20 UTC, Adam D. Ruppe wrote:
On Wednesday, 17 March 2021 at 17:46:27 UTC, uranuz wrote:
Also because it is not a property in some contexts when I try
to concatenate it with string without parentheses using "~"
operator it fails
Can you post some sample code that demonstrates this?
Seems that a problem with concatenation is because
Throwable.message has const(char)[] type, but not string. This
makes some inconvenience ;-)
There is an example:
import std;
void main()
{
auto exc = new Exception("Test");
string longMsg = "The: " ~ exc.message; // Adding parentheses
() after "message" actually doesn't change anything. Error is the
same
writeln(longMsg);
}
Compile error:
onlineapp.d(6): Error: cannot implicitly convert expression "The:
" ~ exc.message() of type char[] to string
I could add cast(string), but it's not something I want to do.
The reason, why I want to use "message" instead of "msg" is that
I want to add some extra information to exception as separate
typed fields. But I want it to be displayed when converting
exception to string. So I shall override "message" and convert
this extra info to string...