On Saturday, 1 April 2017 at 13:34:58 UTC, Andrei Alexandrescu wrote:
Walter and I discussed the following promising setup:

Use "throw new scope Exception" from @nogc code. That will cause the exception to be allocated in a special stack-like region.

If the catching code uses "catch (scope Exception obj)", then a reference to the exception thus created will be passed to catch. At the end of the catch block there's no outstanding reference to "obj" so it will be freed. All @nogc code must use this form of catch.

If the catching code uses "catch (Exception obj)", the exception is cloned on the gc heap and then freed.

Finally, if an exception is thrown with "throw new Exception" it can be caught with "catch (scope Exception obj)" by copying the exception from the heap into the special region, and then freeing the exception on the heap.

Such a scheme preserves backward compatibility and leverages the work done on "scope".


Andrei

(currently using @nogc exceptions with malloc+emplace and destroy+free)

OK. The important bit imho is that exception don't become special class objects.
ie. "scope new" is not specific to exceptions.
The other @nogc blocker is .destroy

Reply via email to