diff --git a/runtime/src/main/java/dev/ionfusion/fusion/FusionException.java b/runtime/src/main/java/dev/ionfusion/fusion/FusionException.java index 837e5431..08799e43 100644 --- a/runtime/src/main/java/dev/ionfusion/fusion/FusionException.java +++ b/runtime/src/main/java/dev/ionfusion/fusion/FusionException.java @@ -20,6 +20,14 @@ * one to throw arbitrary values, not just "exception" types. Within the * FusionJava implementation, all such values are wrapped in * {@link FusionException}s. + *
+ * To show Fusion stack traces when these Java exceptions are printed,
+ * {@link #getMessage()} consists of two parts: the base message} (a
+ * description of the exception) and the context (the Fusion stack
+ * trace).
+ * Rather than simply printing the Java exception, applications and tools may
+ * produce better messages by getting the components individually via
+ * {@link #getBaseMessage()} and {@link #getContext()}.
*/
@SuppressWarnings("serial")
public class FusionException
@@ -31,31 +39,29 @@ public class FusionException
*/
private List
+ * This should be preferred over {@link #getMessage()} since the latter
+ * includes the Fusion continuation trace.
+ *
+ * @return the base message.
*/
- String getBaseMessage()
+ public String getBaseMessage()
{
return super.getMessage();
}
- void displayMessage(Evaluator eval, Appendable out)
- throws IOException, FusionException
- {
- String superMessage = getBaseMessage();
- if (superMessage != null)
- {
- out.append(superMessage);
- }
- }
-
/**
- * @return the base message, followed by the Fusion continuation trace.
+ * Returns the base message of this exception, followed by the Fusion stack
+ * trace.
+ *
+ * @return not null.
*/
@Override
public final String getMessage()
{
StringBuilder out = new StringBuilder();
+ String base = getBaseMessage();
+ if (base == null)
+ {
+ base = getClass().getSimpleName();
+ }
+ out.append(base);
+
try
{
- displayMessage(null, out);
displayContinuation(out);
}
- catch (IOException | FusionException e)
+ catch (IOException e)
{
// Swallow these, we can't do anything with it at the moment.
}