Bug 10989 – [CTFE] Uncaught exception messages are not pretty printed if message wasn't literal
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-07T15:40:00Z
Last change time
2015-02-18T03:41:51Z
Keywords
CTFE, diagnostic, pull
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2013-09-07T15:40:59Z
import std.string;
enum foo = (){
throw new Exception(format("Something %d wicked happened!", 42));
return 0;
}();
On a recent DMD from git master:
D:\D\ctfe_ex.d(4): Error: Uncaught CTFE exception object.Exception(['S', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g', ' ', '4', '2', ' ', 'w', 'i', 'c', 'k', 'e', 'd', ' ', 'h', 'a', 'p', 'p', 'e', 'n', 'e', 'd', '!'][0u..29u])
D:\D\ctfe_ex.d(6): called from here: (*int()
{
throw new Exception(format("Something %d wicked happened!", 42), "D:\\D\\ctfe_ex.d", 4u, null);
return 0;
}
Note that the following using plain literal neatly formats the string:
enum foo = (){
throw new Exception("Something wicked happened!");
return 0;
}();
D:\D\ctfe_ex.d(2): Error: Uncaught CTFE exception object.Exception("Something wicked happened!")
The point is it should always pretty print it unless it contains bad UTF-8.
Comment #1 by clugdbug — 2013-09-10T23:23:00Z
Patch:
--- a/src/ctfeexpr.c
+++ b/src/ctfeexpr.c
@@ -157,7 +157,7 @@ char *ThrownExceptionExp::toChars()
void ThrownExceptionExp::generateUncaughtError()
{
thrown->error("Uncaught CTFE exception %s(%s)", thrown->type->toChars(),
- (*thrown->value->elements)[0]->toChars());
+ (*thrown->value->elements)[0]->toString()->toChars());
/* Also give the line where the throw statement was. We won't have it
* in the case where the ThrowStatement is generated inter
Reduced test case:
enum foo = () { throw new Exception(['a', 'b', 'c']); return 0; }();
Comment #4 by electrolysis.jp+d — 2015-01-05T10:41:28Z
This bug is still alive, at least around the first test case, though Don's reduced one shows a nicer message.
Result:
ctfe_ex.d(4): Error: uncaught CTFE exception object.Exception(['S', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g', ' ', '4', '2', ' ', 'w', 'i', 'c', 'k', 'e', 'd', ' ', 'h', 'a', 'p', 'p', 'e', 'n', 'e', 'd', '!'][0..29])
ctfe_ex.d(6): called from here: (*() => 0)()