Skip to content

Commit

Permalink
add attribute "cause" to tag cfthrow
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 4, 2023
1 parent 46cb2fd commit 8f174e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
15 changes: 14 additions & 1 deletion core/src/main/java/lucee/runtime/tag/Throw.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class Throw extends TagImpl {
private String errorcode = "";

private Object object;
private PageException cause;

private int level = 1;

Expand All @@ -72,6 +73,7 @@ public void release() {
errorcode = "";
object = null;
level = 1;
cause = null;
}

/**
Expand Down Expand Up @@ -118,6 +120,14 @@ public void setMessage(String message) {
this.message = message;
}

public void setCause(Object cause) throws PageException {
if (cause == null) return;
if (cause instanceof ThreadDeath) throw new ApplicationException("cannot set this kind [" + cause.getClass().getName() + "] of exception as caused by");
this.cause = toPageException(cause, null);
if (this.cause == null) throw new ApplicationException("cannot cast this type [" + cause.getClass().getName() + "] to an exception");

}

/**
* set the value errorcode A custom error code that you supply.
*
Expand Down Expand Up @@ -201,7 +211,9 @@ public int doStartTag() throws PageException {
_doStartTag(message);
_doStartTag(object);

throw new CustomTypeException("", detail, errorcode, type, extendedinfo, level);
CustomTypeException exception = new CustomTypeException("", detail, errorcode, type, extendedinfo, level);
if (cause != null) exception.initCause(cause);
throw exception;
}

private void _doStartTag(Object obj) throws PageException {
Expand All @@ -210,6 +222,7 @@ private void _doStartTag(Object obj) throws PageException {
if (pe != null) throw pe;

CustomTypeException exception = new CustomTypeException(Caster.toString(obj), detail, errorcode, type, extendedinfo, level);
if (cause != null) exception.initCause(cause);
throw exception;
}
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/resource/tld/core-base.tld
Original file line number Diff line number Diff line change
Expand Up @@ -8021,6 +8021,13 @@ If you terminate a thread, the thread scope includes an ERROR metadata structure
<rtexprvalue>true</rtexprvalue>
<description>a native java exception Object, if this attribute is defined all other will be ignored</description>
</attribute>
<attribute>
<type>any</type>
<name>cause</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>the cause of the exception created with this tag. This can be a cfcatch block or a native java exception.</description>
</attribute>
<attribute>
<type>numeric</type>
<name>contextLevel</name>
Expand Down
4 changes: 2 additions & 2 deletions loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.0.0.533-SNAPSHOT"/>
<property name="version" value="6.0.0.534-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
<fileset dir="../ant/lib" includes="maven-resolver-ant-tasks-*.jar"/>
<fileset dir="../ant/lib" includes="maven-resolver-ant-tasks-*.jar"/>
</classpath>
</taskdef>

Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.0.0.533-SNAPSHOT</version>
<version>6.0.0.534-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 8f174e8

Please sign in to comment.