From: Nicolas C. <war...@fr...> - 2003-03-03 05:52:29
|
> Good suggestions. > > Another issue: I see (at least) two philosophies of exception naming. > > (1) The standard library only defines a few, and uses string arguments (to > Failure and Invalid_argument) for specifics. > > (2) Nicolas's collection uses more numerous and specific exceptions: > Invalid_index > Invalid_string > No_such_element > ... > > I guess I'm used to the first approach, and the generality hasn't been > a problem. I've almost always been able to write something like > try ... with Failure _ -> ... > and often just > try ... with _ -> ... > rather than being more specific. What has been the experience of > others on this list? We have already been discussing about that ( see the list archives ). The probleme here is that you cannot enclose a large blocs of code within try...with because catching Failure _ or even worst _ can be a very bad thing. So most of the time I suppose you're doing something like : let i = (try int_of_string s with _ -> raise MyException) in .... and then MyException is catched by the up/calling function. This would be easier to have int_of_string directly raising your exception. Exceptions are made to propagate, and Failure / Invalid_arguments are good for either immediate catching or no-catching at all . Nicolas Cannasse |