Created
September 12, 2023 08:00
-
-
Save trycf/ec53d0f523690c645ae8fe518e89f0b5 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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