如何向 ColdFusion 异常对象添加属性
我知道这看起来一定是一个非常人为的例子,但我有一个情况,在一个 catch 中我将尝试/捕获另一个异常。但是,我想在第二个捕获中包含有关第一个异常的信息。理想情况下,它看起来像这样:
try {
a = b;
}
catch ( any e ) {
local.originalException = Duplicate(e);
try {
throw "New exception!!!";
}
catch( any e ) {
e.originalException = local.originalException;
doNotification( e );
}
}
当我运行这个小测试时,设置 e.originalException 时不会发生意外异常,但是,当我在设置后立即转储异常时,它不是异常结构的一部分。也许还有另一种方法可以实现这一目标吗?我用的是ACF 9。
I know this must seem like a very contrived example, but I have a case in which within a catch I will be try/catching another exception. However, I would like to include information in the second catch about the first exception. Ideally it would look something like this:
try {
a = b;
}
catch ( any e ) {
local.originalException = Duplicate(e);
try {
throw "New exception!!!";
}
catch( any e ) {
e.originalException = local.originalException;
doNotification( e );
}
}
When I run this little test, there is no unexpected exception that occurs when setting e.originalException, however, when I dump the exception immediately after setting it, it is not a part of the exception struct. Is there perhaps another way to achieve this? I am using ACF 9.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,您实际上无法将太多附加信息“附加”到 CF 异常。但是你可以做这样的事情来将一个异常包装在另一个异常中......
这种技术对你有帮助吗?
You can't really "attach" much additional info to a CF exception, unfortunately. But you could do something like this to wrap up one exception in another one...
Does this sort of technique help you?
您是否尝试过复制该对象?因为根据 文档,您无法修改 cfcatch 异常:
Did you try duplicating the object? Because according to the documentation you cannot modify cfcatch exceptions:
我知道我回答“有点”晚了,但我遇到了同样的问题,这就是我解决它的方法:
I know I'm a "bit" late to answer, but I ran into the same issue and this is how I got around it: