From: jsimomaa Date: Thu, 4 Jan 2018 07:56:34 +0000 (+0200) Subject: Add more Throwable & Exception handling functionality to Prelude X-Git-Tag: v1.43.0~136^2~639 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=e9757cdfe5996d87738cabad84bff0343f56e4e3;ds=sidebyside Add more Throwable & Exception handling functionality to Prelude refs #7705 Change-Id: Ie335d3e8f7dacb0da66d0bb1491862fb054c61cb --- diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index a926ae40e..eb8026de9 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -2214,6 +2214,12 @@ importJava "java.lang.Throwable" where @private @JavaName toString showThrowable :: Throwable -> String + @private + @JavaName getMessage + getMessageThrowable :: Throwable -> String + @private + @JavaName getCause + getCauseThrowable :: Throwable -> Maybe Throwable importJava "java.lang.Exception" where data Exception @private @@ -2225,6 +2231,20 @@ instance Show Throwable where instance Show Exception where show = showException +class Throwable e where + toThrowable :: e -> Throwable + +messageOfException :: Throwable e => e -> String +messageOfException = getMessageThrowable . toThrowable + +causeOfException :: Throwable e => e -> Maybe Throwable +causeOfException = getCauseThrowable . toThrowable + +instance Throwable Throwable where + toThrowable = id +instance Throwable Exception where + toThrowable = Java.unsafeCoerce + "Prints the given value in the console." @inline print :: Show a => a -> ()