Skip to content

Commit

Permalink
objectionary#2772: safeMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Jan 15, 2024
1 parent 60bdcf9 commit 1520778
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion eo-runtime/src/main/java/EOorg/EOeolang/EOerror.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static final class ExError extends ExAbstract {
* @param enclosure Enclosure inside the error
*/
public ExError(final Phi enclosure) {
super(new PhContainingUTF8(enclosure).toString());
super(EOerror.ExError.safeMessage(enclosure));
this.enc = enclosure;
}

Expand All @@ -127,5 +127,29 @@ public ExError(final Phi enclosure) {
public Phi enclosure() {
return this.enc;
}

/**
* Retrieve message from enclosure safely.
* @param enclosure Enclosure.
* @return String message.
* @checkstyle IllegalCatchCheck (20 lines)
*/
private static String safeMessage(final Phi enclosure) {
String result;
if (enclosure == null) {
result = "null Phi";
} else {
try {
result = new PhContainingUTF8(enclosure).toString();
} catch (final Throwable first) {
try {
result = enclosure.toString();
} catch (final Throwable second) {
result = enclosure.getClass().toString();
}
}
}
return result;
}
}
}

0 comments on commit 1520778

Please sign in to comment.