Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom error or not

30 views
Skip to first unread message

Cecil Westerhof

unread,
Feb 1, 2018, 7:44:06 AM2/1/18
to
I am using a function to get a default database so I do not have to
work with configuration files. Something like:
proc ::dcblUtilities::getDefaultDB {{key ""} {DB db} {timeoutSecs 10} \
{configDB ~/.tcl.sqlite}} {
When the key is empty, I use the scriptname as key.

When no key can be retrieved, I give an error:
error "Cannot retrieve database for ${key}"

But what is the tcl way when something goes wrong with opening the
database(s): let the error propagate, or catching the error and
throwing my own error?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Gerald Lester

unread,
Feb 1, 2018, 10:22:20 AM2/1/18
to
On 02/01/2018 06:21 AM, Cecil Westerhof wrote:
> I am using a function to get a default database so I do not have to
> work with configuration files. Something like:
> proc ::dcblUtilities::getDefaultDB {{key ""} {DB db} {timeoutSecs 10} \
> {configDB ~/.tcl.sqlite}} {
> When the key is empty, I use the scriptname as key.
>
> When no key can be retrieved, I give an error:
> error "Cannot retrieve database for ${key}"
>
> But what is the tcl way when something goes wrong with opening the
> database(s): let the error propagate, or catching the error and
> throwing my own error?

Either way -- it depends on what you will think is clearer to the person
using your code.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Cecil Westerhof

unread,
Feb 1, 2018, 12:59:06 PM2/1/18
to
Gerald Lester <Gerald...@KnG-Consulting.net> writes:

> On 02/01/2018 06:21 AM, Cecil Westerhof wrote:
>> I am using a function to get a default database so I do not have to
>> work with configuration files. Something like:
>> proc ::dcblUtilities::getDefaultDB {{key ""} {DB db} {timeoutSecs 10} \
>> {configDB ~/.tcl.sqlite}} {
>> When the key is empty, I use the scriptname as key.
>>
>> When no key can be retrieved, I give an error:
>> error "Cannot retrieve database for ${key}"
>>
>> But what is the tcl way when something goes wrong with opening the
>> database(s): let the error propagate, or catching the error and
>> throwing my own error?
>
> Either way -- it depends on what you will think is clearer to the person
> using your code.

That you do not know when writing a public package. (I am going to
publish it on GitHub.) But I think that I will catch and throw my own
error.

Gerald Lester

unread,
Feb 1, 2018, 2:01:24 PM2/1/18
to
A public package -- in that case I agree it should furnish its own error
if it is an "expected" or known issue.
0 new messages