On Friday, 8 March 2013 at 01:56:45 UTC, Andrej Mitrovic wrote:
On 3/8/13, Rob T <[email protected]> wrote:
In C++, I rethrow an exception without explicitly catching it
catch(...)
{
throw;
}
Anyone know of a way to do the same thing in D?
catch
{
// rethrow?
}
The only way:
try { }
catch (Exception ex) { throw ex; }
Or use Error or Throwable if really necessary, however you
shouldn't
really catch those in normal code.
That's very unfortunate, and should be corrected, because it
means that you cannot easily catch multiple derived Exception
types and rethrow the same derived type. Instead you have to
explicitly catch all derived types and rethrow them individually,
but that's simply not practical, so you end up catching only the
base exception (Throwable?) and rethrow it, but you lose the
derived type in the process.
--rt