如何阻止DevForce在EntityManager.EntityChanged事件中吞下异常 [英] How can I stop DevForce from swallowing exceptions in the EntityManager.EntityChanged event

查看:90
本文介绍了如何阻止DevForce在EntityManager.EntityChanged事件中吞下异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是DevForce论坛此处。问题在于,如果更改是由查询或导入触发的,DevForce将以静默方式吞并EntityManager.EntityChanged事件引发的任何异常。相关代码如下:

This is yet another continuation of a thread from the DevForce forums here. The problem is that DevForce will silently swallow any exception that gets thrown by the EntityManager.EntityChanged event if the change was triggered by a query or import. The relevant code looks like this:

internal virtual void OnEntityChanged(EntityChangedEventArgs args)
{
    EventHandler<EntityChangedEventArgs> entityChanged = this.EntityChanged;
    if (entityChanged == null) return;
    try
    {
        entityChanged(this, args);
    }
    catch
    {
        if (args.Action != EntityAction.AddOnQuery && args.Action != EntityAction.AddOnImport)
        {
            throw;
        }
    }
}

如论坛主题所述,这种方法的行为随着时间的推移有所变化。现在吞下的东西比我第一次抱怨时要少。但是对于我们的应用程序,我们确实需要知道什么时候出了问题。仅仅因为我执行查询或导入操作时发生错误并不意味着我不在乎该异常。

As mentioned in the forum thread, the behavior of this method has changed a bit overtime. Less things are swallowed now than they were when I first complained about this. But for our application, we really need to know when anything goes wrong. Just because it happened to go wrong when I did a query or an import operation does not mean that I don't care about the exception.

在上一个论坛帖子中,这种行为的原因是:

In the last forum post, the rationale for this behavior was:


吞下在AddOnQuery(和
AddOnImport)期间引发的异常的论点是查询的中间通常不是开发人员实际想要的
,因为由于事件处理程序的编写不当,更有可能
发生

The argument for swallowing exceptions thrown during AddOnQuery (and AddOnImport) was that "failing in the middle of a query is usually not what the developer actually intended" because it was more likely to occur due to a badly written event handler

也许我们不是平常的:-),但是在我们的应用程序中,事件处理程序看起来像这样:

Perhaps we aren't usual :-), but in our application, the event handler looks like this:

EntityManager.EntityChanged += (sender, e) =>
{
    if (e.Action == EntityAction.AddOnAttach ||
        e.Action == EntityAction.AddOnImport ||
        e.Action == EntityAction.AddOnQuery)
    {
        ((MyBaseClass) e.Entity).Initialize();
    }
};

在这里抛出的任何异常都不是因为事件处理程序的编写不正确。这里抛出的任何异常是因为实体在执行其一次性初始化逻辑时变得非常困惑。而且该逻辑中的错误对我们来说非常重要。

Any exception thrown here are not going to be because of a badly written event handler. Any exception that gets thrown here is because the entity got very confused while it was doing its one-time initialization logic. And errors in that logic are very important to us.

我可以理解,普遍更改此设置可能很危险,并且会导致其他应用程序开始崩溃。但是,如果有某种方法可以关闭此行为,或者以其他方式告诉实体管理器不要吞下该异常,那将非常非常有帮助。

I can understand that changing this universally might be dangerous and cause other application to start breaking. But if there was some way that we could turn off this behavior or some other way to tell the Entity Manager not to swallow the exception, that would be very, very helpful.

我们以前的解决方法开始失败,因为我们希望在Web服务中使用所有业务逻辑,而我们不能仅仅依靠错误日志记录来处理这种情况。事情。我们不能仅仅因为DevForce吞下了一个潜在的致命错误就向呼叫者返回成功响应。

Our previous workarounds are starting to fail as we look to use all our business logic in a Web Service where we can't just rely on error logging to handle this kind of thing. We can't be returning a 'success' response to the caller just because DevForce swallowed a potentially fatal error.

我们使用的是最新版本的DevForce(截至目前写作:2012年-7.2.3)。

We are on the latest version of DevForce (as of this writing: 2012 - 7.2.3).

推荐答案

版本7.2.4包含一个标志EntityManagerOptions.ThrowAllLoadExceptions,以控制此行为。 发行说明。

Version 7.2.4 contains a flag, EntityManagerOptions.ThrowAllLoadExceptions, to control this behavior. Release notes.

这篇关于如何阻止DevForce在EntityManager.EntityChanged事件中吞下异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆