D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6245 - Using an exception object inside a delegate, causes a crash
Summary: Using an exception object inside a delegate, causes a crash
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-03 19:03 UTC by Carlos Ballesteros Velasco
Modified: 2022-08-15 14:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Carlos Ballesteros Velasco 2011-07-03 19:03:00 UTC
import std.stdio;

void callDelegate(void delegate() cb) {
	cb();
}

void writeEx(Throwable o) {
	writefln("%s", o);
}

void works1() {
	Throwable o2;
	try {
		throw(new Exception("This is an error"));
	} catch (Throwable o) {
		o2 = o;
		callDelegate({
			writefln("%s", o2);
		});
	}
}

void works2() {
	try {
		throw(new Exception("This is an error"));
	} catch (Throwable o) {
		writeEx(o);
	}
}

void do_not_work() {
	try {
		throw(new Exception("This is an error"));
	} catch (Throwable o) {
		callDelegate({
			writefln("%s", o);
		});
	}
}

int main(string[] args) {
	works1();
	works2();
	do_not_work();
	return 0;
}
Comment 1 SomeDude 2012-04-24 12:07:35 UTC
Confirmed with 2.059
Comment 2 RazvanN 2022-08-15 14:43:45 UTC
I just compiled and ran the code with the latest master. It successfully compiles, runs and exits gracefully. It seems like this has been fixed.