diff options
Diffstat (limited to 'stdlib/source/library/lux/control/exception.lux')
-rw-r--r-- | stdlib/source/library/lux/control/exception.lux | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 9a9e7f845..f89611e19 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -28,18 +28,14 @@ ["//" try (#+ Try)]]) (type: .public (Exception a) - {#.doc "An exception provides a way to decorate error messages."} {#label Text #constructor (-> a Text)}) (def: .public (match? exception error) - {#.doc (example "Is this exception the cause of the error message?")} (All [e] (-> (Exception e) Text Bit)) (text.starts_with? (get@ #label exception) error)) (def: .public (when exception then try) - {#.doc (example "If a particular exception is detected on a possibly-erroneous value, handle it." - "If no exception was detected, or a different one from the one being checked, then pass along the original value.")} (All [e a] (-> (Exception e) (-> Text a) (Try a) (Try a))) @@ -52,12 +48,11 @@ (if (text.starts_with? reference error) (#//.Success (|> error (text.clip' (text.size reference)) - maybe.assume + maybe.trusted then)) (#//.Failure error))))) (def: .public (otherwise else try) - {#.doc "If no handler could be found to catch the exception, then run a function as a last-resort measure."} (All [a] (-> (-> Text a) (Try a) a)) (case try @@ -68,12 +63,10 @@ (else error))) (def: .public (error exception message) - {#.doc "Constructs an error message from an exception."} (All [e] (-> (Exception e) e Text)) ((get@ #..constructor exception) message)) (def: .public (except exception message) - {#.doc "Decorate an error message with an Exception and lift it into the error-handling context."} (All [e a] (-> (Exception e) e (Try a))) (#//.Failure (..error exception message))) @@ -98,15 +91,9 @@ ))) (syntax: .public (exception: [[export_policy t_vars [name inputs] body] ..exception]) - {#.doc (example "Define a new exception type." - "It mostly just serves as a way to tag error messages for later catching." + {#.doc (example "" - "Simple case:" - (exception: .public some_exception) - "" - "Complex case:" - (exception: .public [arbitrary type variables] (some_exception {optional Text} {arguments Int}) - optional_body))} + )} (macro.with_identifiers [g!descriptor] (do meta.monad [current_module meta.current_module_name @@ -132,14 +119,14 @@ on_new_line (|> " " (list.repeated (n.+ (text.size header_separator) largest_header_size)) - (text.join_with "") + text.joined (text\compose text.new_line)) on_entry (: (-> [Text Text] Text) (function (_ [header message]) (let [padding (|> " " (list.repeated (n.- (text.size header) largest_header_size)) - (text.join_with ""))] + text.joined)] (|> message (text.replaced text.new_line on_new_line) ($_ text\compose padding header header_separator)))))] @@ -154,19 +141,11 @@ tail)))) (syntax: .public (report [entries (<>.many (<code>.tuple (<>.and <code>.any <code>.any)))]) - {#.doc (example "An error report." - (: Text - (report ["Row 0" value/0] - ["Row 1" value/1] - ,,, - ["Row N" value/N])))} (in (list (` ((~! report') (list (~+ (|> entries (list\map (function (_ [header message]) (` [(~ header) (~ message)]))))))))))) (def: .public (listing format entries) - {#.doc (example "A numbered report of the entries on a list." - "NOTE: 0-based numbering.")} (All [a] (-> (-> a Text) (List a) Text)) (|> entries @@ -181,7 +160,7 @@ (def: separator (let [gap ($_ "lux text concat" text.new_line text.new_line) - horizontal_line (|> "-" (list.repeated 64) (text.join_with ""))] + horizontal_line (|> "-" (list.repeated 64) text.joined)] ($_ "lux text concat" gap horizontal_line @@ -195,7 +174,6 @@ error)) (def: .public (with exception message computation) - {#.doc (example "If a computation fails, prepends the exception to the error.")} (All [e a] (-> (Exception e) e (Try a) (Try a))) (case computation (#//.Failure error) |