Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/ec53d0f523690c645ae8fe518e89f0b5 to your computer and use it in GitHub Desktop.
Save trycf/ec53d0f523690c645ae8fe518e89f0b5 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
function throwWithCause(required string msg, required cause) {
// sadly CFML does not allow access to methods of a object implementing the collection interface
if(isInstanceOf(cause,"lucee.runtime.exp.CatchBlock")) {
var meta=getMetaData(cause);
var getPageException=meta.getMethod("getPageException",[]);
cause=getPageException.invoke(cause,[]);
}
else if(!isInstanceOf(cause,"java.lang.Exception")) {
throw "cause must be a catch block or an exception";
}
// create the exception
try {
throw msg;
}
catch(e) {
var meta=getMetaData(e);
var getPageException=meta.getMethod("getPageException",[]);
var exp=getPageException.invoke(e,[]);
exp.initCause(cause);
throw e;
}
}
try {
throw "upsi dupsi!";
}
catch(e) {
try {
throwWithCause("Upseli dupseli", e);
}
catch(e) {
// i'm just catching and echo the exception because trycf would swollow most of it
echo(e);
}
//throwWithCause("Upseli dupseli", e);
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment