English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Exceptions inside assertions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-11-12 (09:00)
From: Gerd Stolpmann <Gerd.Stolpmann@d...>
Subject: Exceptions inside assertions

I have a problem with exceptions which are raised within the expression of an
assertion, e.g.

assert (raise Not_found)

The current behaviour is that the exception "falls through the assertion" which
may not be appropriate for some cases. For example, consider

assert (Queue.peek queue == current_element)

>From my point of view, the assertion expresses that "queue" has at least one
element and that this element is identical to "current_element". But if the
assertion is violated because the queue is empty, I only get a Queue.Empty
exception, and I do not see the reason for it. Perhaps I even catch
Queue.Empty, and the program continues, which is very hard to find out.

I suggest to introduce a new Assert_failure_by_exception exception to better
report this situation.

Gerd Stolpmann      Telefon: +49 6151 997705 (privat)
Viktoriastr. 100             
64293 Darmstadt     EMail:   Gerd.Stolpmann@darmstadt.netsurf.de (privat)