[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] pkl: Add exception_new to register user-defined exceptions
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] pkl: Add exception_new to register user-defined exceptions |
Date: |
Mon, 25 Jan 2021 12:43:20 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
>> > This commit introduces a new function `exception_new` to give an
>> > `Exception` value with a unique `code` number.
>> > (Based on your suggestion a while ago in IRC).
>>
>> I like the approach.
>>
>> However, this couples the contents of exceptions with the
>> `exception_new' generator.
>>
>> What is really generated is the exception code, so what about having an
>> `exception_code' generator. User-defined exceptions would then be
>> defined like:
>>
>> var E_my_exception = Exception { code = exception_new, ... };
>>
>> WDYT?
>>
>
> I considered both approaches and chose the approach that I thought
> is more user-friendly.
> User just wants to define a new exception and don't need to be concerned
> about the `code` field.
Well, users can already build exceptions using standard codes, like:
raise Exception {code = EC_generic,
msg = "unknown option -" + arg};
So generally speaking they should be aware of codes. All the other
fields of an Exception have default values, so the user doesn't need to
be concerned with them. I think that's enough abstraction.
> But OK, I'll send the new patch soon.
Thanks!