Skip to content

Commit

Permalink
manual: document exception A | pat
Browse files Browse the repository at this point in the history
  • Loading branch information
Octachron committed Dec 7, 2018
1 parent f86d10a commit 685eed9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions manual/manual/refman/patterns.etex
Expand Up @@ -179,8 +179,9 @@ instance, the pattern "'0'"@'..'@"'9'" matches all characters that are digits.
\subsubsection*{Exception patterns} \label{s:exception-match}
(Introduced in OCaml 4.02)

A new form of exception pattern, @ 'exception' pattern, @ is allowed
only as a toplevel pattern under a "match"..."with" pattern-matching
A new form of exception pattern,
@ 'exception' pattern @, is allowed only as a toplevel pattern or inside
a toplevel or-pattern under a "match"..."with" pattern-matching
(other occurrences are rejected by the type-checker).

Cases with such a toplevel pattern are called ``exception cases'',
Expand Down
14 changes: 10 additions & 4 deletions manual/manual/tutorials/coreexamples.etex
Expand Up @@ -550,10 +550,16 @@ let assoc_may_map f x l =
| y -> f y;;
\end{caml_example}
Note that this construction is only useful if the exception is raised
between "match"\ldots"with". Moreover, exceptions can only
appear at the toplevel of such a pattern match.
For instance, exception cases cannot currently be combined with an
or-pattern: "exception A | exception B ->" \ldots .
between "match"\ldots"with". Exception patterns can be combined
with ordinary patterns at the toplevel,
\begin{caml_example}{toplevel}
let find x l =
match List.assoc_opt x l with
| None | exception Not_found -> None
| Some _ as v -> v;;
\end{caml_example}
but they cannot be nested inside other patterns. For instance,
the pattern "Some (exception A)" is invalid.

When exceptions are used as a control structure, it can be useful to make
them as local as possible by using a locally defined exception.
Expand Down

0 comments on commit 685eed9

Please sign in to comment.