Skip to content

Commit d3c2be9

Browse files
authored
Merge pull request #8795 from ntrel/ex-panels
[std/exception] Tweak docs Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com> Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 3a8d501 + d31490e commit d3c2be9

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

std/exception.d

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,16 @@ void assertThrown(T : Throwable = Exception, E)
416416
Returns: `value`, if `cast(bool) value` is true. Otherwise,
417417
depending on the chosen overload, `new Exception(msg)`, `dg()` or `ex` is thrown.
418418
419-
Note:
420-
`enforce` is used to throw exceptions and is therefore intended to
419+
$(PANEL
420+
$(NOTE `enforce` is used to throw exceptions and is therefore intended to
421421
aid in error handling. It is $(I not) intended for verifying the logic
422-
of your program. That is what `assert` is for. Also, do not use
422+
of your program - that is what `assert` is for.)
423+
424+
Do not use
423425
`enforce` inside of contracts (i.e. inside of `in` and `out`
424426
blocks and `invariant`s), because contracts are compiled out when
425427
compiling with $(I -release).
428+
)
426429
427430
If a delegate is passed, the safety and purity of this function are inferred
428431
from `Dg`'s safety and purity.
@@ -836,7 +839,7 @@ string letters()
836839
)
837840
838841
The use in the example above is correct because `result`
839-
was private to `letters` and is inaccessible in writing
842+
was private to `letters` and the memory it referenced can no longer be written to
840843
after the function returns. The following example shows an
841844
incorrect use of `assumeUnique`.
842845
@@ -859,22 +862,23 @@ string letters(char first, char last)
859862
----
860863
)
861864
862-
The example above wreaks havoc on client code because it is
863-
modifying arrays that callers considered immutable. To obtain an
865+
The example above wreaks havoc on client code because it modifies the
866+
returned array that the previous caller considered immutable. To obtain an
864867
immutable array from the writable array `buffer`, replace
865868
the last line with:
866869
867870
----
868871
return to!(string)(sneaky); // not that sneaky anymore
869872
----
870873
871-
The call will duplicate the array appropriately.
874+
The `to` call will duplicate the array appropriately.
872875
873-
Note that checking for uniqueness during compilation is
876+
$(PANEL
877+
$(NOTE Checking for uniqueness during compilation is
874878
possible in certain cases, especially when a function is
875-
marked as a pure function. The following example does not
879+
marked (or inferred) as `pure`. The following example does not
876880
need to call `assumeUnique` because the compiler can infer the
877-
uniqueness of the array in the pure function:
881+
uniqueness of the array in the pure function:)
878882
879883
$(RUNNABLE_EXAMPLE
880884
----
@@ -894,6 +898,7 @@ For more on infering uniqueness see the $(B unique) and
894898
$(B lent) keywords in the
895899
$(HTTP www.cs.cmu.edu/~aldrich/papers/aldrich-dissertation.pdf, ArchJava)
896900
language.
901+
)
897902
898903
The downside of using `assumeUnique`'s
899904
convention-based usage is that at this time there is no

0 commit comments

Comments
 (0)