|
2016-07-14
| ||
| 08:09 | • Ticket [c128108271] Allow globs in trap patterns status still Open with 6 ot... artifact: 81762af683 user: dkf | |
|
2016-07-13
| ||
| 07:49 | • New ticket [c128108271]. artifact: ee6ab741b1 user: adrianmedranocalvo | |
Allow globs in trap patterns
Openc1281082718e963be1b5c30ad0be9e895d26b40eCreated 10 years agoUpdated 10 years ago
Descriptionplain2016-07-13 07:49:14
At the moment "trap" clauses in the "try" command must exactly match the -errorcode prefix. It would be useful being able to specify glob patterns for each of the -errorcode words.
For example, given two TclOO subclasses implementing an interface (e.g. they share the superclass), we might want to prefix all -errorcodes with the class name similarly to how Tcl core prefixes all its errors with TCL. Trapping an error from either subclass can be done at the moment as follows:
try {
$a feed $x;
} trap {::cow BADFOOD} {} - trap {::human BADFOOD} {} {
$a drink;
}
This becomes an issue when when adding a new ::animal subclass ::fly: the code above must be changed to take it into account.
If globbing were allowed in trap patterns, the same could be accomplished as follows:
try {
$a feed $x;
} trap {* BADFOOD} {} {
$a drink
}
This new behaviour could be specified via a flag similar to switch's -glob and -regexp.
dkfwiki2016-07-14 08:09:27
Why not use the class name as a suffix? Then the existing prefix machinery will “just work”.
Log in (anonymous is fine) to add a comment.