On Wed, 17 Feb 2016 01:09:20 +0000, Adam D. Ruppe wrote: > On Wednesday, 17 February 2016 at 00:45:35 UTC, Chris Wright wrote: >> http://dpldocs.info/search/search?searchTerm=emplace to create an >> exception object in manually allocated memory. > > Aye, this overload: > http://dpldocs.info/experimental-docs/std.conv.emplace.3.html > > though the example there is awful, wtf is it even trying to show? > > > But anyway, you can also throw a static object. That's actually what > outOfMemoryError does > <http://dpldocs.info/experimental-docs/ core.exception.onOutOfMemoryError.html> > - it throws a statically allocated object.
Sure, but that's pretty annoying. You have to ensure that you will never need to throw two of the same exception at the same time -- or you allocate several statically and go through hoops to ensure you're using one that's not currently in use. It's a lot easier to malloc and free exceptions. Since they're presumably only cropping up in exceptional circumstances, there's a lot less worry about making many small allocations.
