[Ur] Exceptions handling

Vladimir Shabanov vshabanoff at gmail.com
Tue Aug 24 11:29:08 EDT 2010


2010/8/24 Adam Chlipala <adamc at impredicative.com>:
> Vladimir Shabanov wrote:
>>
>> Ur/Web can throw error on invalid DML (for example "ERROR: duplicate
>> key value violates unique constraint ..."). Currently this error
>> results in invalid page.
>>
>> Is there a way to handle such errors?
>>
>
> No, there is no support for that right now.  Do you have a suggestion of
> what support you would like to see?

There are several ways to add exceptions.

For catching and throwing special syntax (try ... with ..., or ...
handle .. => .., or try .. catch ..) can be added or it can be done
using functions, like
val catch : transaction t -> (exc -> transaction t) -> transaction t
val throw : exc -> transaction t
or more generic
val catch : a -> (exc -> a) -> a
val throw : exc -> a

I prefer functions (they doesn't look like something built in,
although they are), but Ur doesn't support Haskell-like syntax  ...
`catch` \ e -> ..., so maybe special syntax is more adequate (since it
is shorter).

As for exception types there are also several ways:
1. fixed builtin datatype Error = ErrorCall string | DBError ... |
OtherError (as in old haskell)
2. user extensible type exc and separate 'exception MyError of string'
declarations (as in ocaml)
3. exception type class, with any user data type can be made instance
of this class (as in current haskell)
4. something with polymorphic variants:
      catch (throw [#SomeError] "uhoh") (fn e =>
          match e {SomeError x => ...}
   or with lighter syntax
     throw [#SomeError] "uhoh" handle SomeError x => ...

First way can be the simplest one to implement, last way can be the
simplest for programmer (no need to declare anything for user
exceptions). #3 also ok, and #2 I like lesser than others.

In general there should not be many exceptions in Ur (they all come
from external sources, not from Ur itself, except probably some user
input validation errors) so maybe simplest case would be enough.

It also be nice to have same exception handling in client code (e.g.
to catch exceptions from rpc same way as in usual code).



More information about the Ur mailing list