Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit a46f582

Browse files
committed
Changed Throwable.toString to only print the current exception, not the entire chain. Also added support for Error.bypassedException in the uncaught exception display code.
1 parent 1ea100c commit a46f582

File tree

2 files changed

+86
-43
lines changed

2 files changed

+86
-43
lines changed

src/object_.d

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,24 +1253,23 @@ class Throwable : Object
12531253
char[20] tmp = void;
12541254
char[] buf;
12551255

1256-
for (Throwable e = this; e !is null; e = e.next)
1256+
if (file)
12571257
{
1258-
if (e.file)
1259-
{
1260-
buf ~= e.classinfo.name ~ "@" ~ e.file ~ "(" ~ tmp.intToString(e.line) ~ "): " ~ e.msg;
1261-
}
1262-
else
1263-
{
1264-
buf ~= e.classinfo.name ~ ": " ~ e.msg;
1265-
}
1266-
if (e.info)
1267-
{
1268-
buf ~= "\n----------------";
1269-
foreach (t; e.info)
1270-
buf ~= "\n" ~ t;
1271-
}
1272-
if (e.next)
1273-
buf ~= "\n";
1258+
buf ~= this.classinfo.name ~ "@" ~ file ~ "(" ~ tmp.intToString(line) ~ ")";
1259+
}
1260+
else
1261+
{
1262+
buf ~= this.classinfo.name;
1263+
}
1264+
if (msg)
1265+
{
1266+
buf ~= ": " ~ msg;
1267+
}
1268+
if (info)
1269+
{
1270+
buf ~= "\n----------------";
1271+
foreach (t; info)
1272+
buf ~= "\n" ~ t;
12741273
}
12751274
return cast(string) buf;
12761275
}

src/rt/dmain2.d

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -395,40 +395,84 @@ extern (C) int main(int argc, char** argv)
395395

396396
void tryExec(scope void delegate() dg)
397397
{
398+
void printLocLine(Throwable t)
399+
{
400+
if (t.file)
401+
{
402+
console(t.classinfo.name)("@")(t.file)("(")(t.line)(")");
403+
}
404+
else
405+
{
406+
console(t.classinfo.name);
407+
}
408+
console("\n");
409+
}
410+
411+
void printMsgLine(Throwable t)
412+
{
413+
if (t.file)
414+
{
415+
console(t.classinfo.name)("@")(t.file)("(")(t.line)(")");
416+
}
417+
else
418+
{
419+
console(t.classinfo.name);
420+
}
421+
if (t.msg)
422+
{
423+
console(": ")(t.msg);
424+
}
425+
console("\n");
426+
}
427+
428+
void printInfoBlock(Throwable t)
429+
{
430+
if (t.info)
431+
{
432+
console("----------------\n");
433+
foreach (i; t.info)
434+
console(i)("\n");
435+
console("----------------\n");
436+
}
437+
}
438+
439+
void print(Throwable t)
440+
{
441+
Throwable firstWithBypass = null;
442+
443+
for (; t; t = t.next)
444+
{
445+
printMsgLine(t);
446+
printInfoBlock(t);
447+
auto e = cast(Error) t;
448+
if (e && e.bypassedException)
449+
{
450+
console("Bypasses ");
451+
printLocLine(e.bypassedException);
452+
if (firstWithBypass is null)
453+
firstWithBypass = t;
454+
}
455+
}
456+
if (firstWithBypass is null)
457+
return;
458+
console("=== Bypassed ===\n");
459+
for (t = firstWithBypass; t; t = t.next)
460+
{
461+
auto e = cast(Error) t;
462+
if (e && e.bypassedException)
463+
print(e.bypassedException);
464+
}
465+
}
398466

399467
if (trapExceptions)
400468
{
401469
try
402470
{
403471
dg();
404472
}
405-
catch (Throwable e)
473+
catch (Throwable t)
406474
{
407-
/+
408-
while (e)
409-
{
410-
if (e.file)
411-
{
412-
// fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg);
413-
console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.msg)("\n");
414-
}
415-
else
416-
{
417-
// fprintf(stderr, "%.*s\n", e.toString());
418-
console (e.toString)("\n");
419-
}
420-
if (e.info)
421-
{
422-
console ("----------------\n");
423-
foreach (t; e.info)
424-
console (t)("\n");
425-
}
426-
if (e.next)
427-
console ("\n");
428-
e = e.next;
429-
}
430-
+/
431-
console (e.toString)("\n");
475+
print(t);
432476
result = EXIT_FAILURE;
433477
}
434478
}

0 commit comments

Comments
 (0)