The Right Approach to Exceptions

Jacob Carlborg doob at me.com
Sun Feb 19 06:54:29 PST 2012


On 2012-02-19 13:27, Juan Manuel Cabo wrote:
> How about adding a string[string] or a variant[string] to the Exception
> class, so one can know details about the subclassed exception without
> downcasting? How ugly would that be?
>
> For instance:
>
> ...
> catch (Exception ex) {
> if ("transient" in ex.details) {
> repeatOneMoreTime();
> }
> if ("i18n_code" in ex.details) {
> log(translate(ex.details["i18n_code"]));
> }
> }
> ...
>
> Details can be standard by convention or otherwise custom.
> (I can see that this can lead to messy proliferation of details, but at
> least solves most of the issues).

How would you know which keys are available in "ex.details", documentation?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list