biztalk 2006 R2 中的异常处理

发布于 2024-08-24 22:06:53 字数 1459 浏览 8 评论 0原文

我有一个 Biztalk 2006 R2 项目(与 ESB 指南 1 一起使用) 我正在从编排调用 C# 代码中的静态方法,该方法使用一个类将文件数据加载到第 0 部分的 xlang 消息正文中 当我传递不存在的文件路径时,内部类捕获异常但不抛出它(在静态方法中有一个 catch 块,在编排中有对异常的真正处理)

静态方法是:


public static XLANGMessage LoadFileIntoMessage(XLANGMessage message, string filePath,Encoding encoding)
        {
            try
            {
                IStreamFactory sf = new FileStreamFactory(filePath,encoding);

                message[0].LoadFrom(sf);
                return message;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

加载文件流的类是:


private class FileStreamFactory : IStreamFactory
        {
            string _fname;
            Encoding _encoding;

            public FileStreamFactory(string fname,Encoding encoding)
            {
                _fname = fname;
                _encoding = encoding;
            }

            public Stream CreateStream()
            {
                try
                {
                    StreamReader sr;
                    sr = new StreamReader
                    (
                        _fname,
                        _encoding
                    );

                    return sr.BaseStream;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

我从编排中调用静态方法,并期望在类和方法获取它之后捕获编排中的异常。

I have a Biztalk 2006 R2 project (used with ESB Guidance 1)
I am calling from orchstration to a static method in c# code, this method uses a class to load a file data into xlang message body at part 0
When I pass filepath which doesn't exist the inside class catch the exception but don't throw it up (in the static method there is a catch block and in the orchstration there is the real handling of the exception)

The static method is:


public static XLANGMessage LoadFileIntoMessage(XLANGMessage message, string filePath,Encoding encoding)
        {
            try
            {
                IStreamFactory sf = new FileStreamFactory(filePath,encoding);

                message[0].LoadFrom(sf);
                return message;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

The Class which load the file stream is :


private class FileStreamFactory : IStreamFactory
        {
            string _fname;
            Encoding _encoding;

            public FileStreamFactory(string fname,Encoding encoding)
            {
                _fname = fname;
                _encoding = encoding;
            }

            public Stream CreateStream()
            {
                try
                {
                    StreamReader sr;
                    sr = new StreamReader
                    (
                        _fname,
                        _encoding
                    );

                    return sr.BaseStream;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

I call the static method from the orchestration and expect to catch the exception in my orchestration after the class and the method gets it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残花月 2024-08-31 22:06:53

我不确定这里的实际问题是什么......您是在谈论如何捕获编排中的异常吗?如何让它进入ESB异常处理系统或者什么?

要处理编排中的异常,您需要使用范围形状(在其中放入可以引发异常的代码/形状),然后向其添加异常处理程序(有点像 try/catch 块)。

有关 ESB 的内容,请参见此处: http:// /msdn.microsoft.com/en-US/library/ee250235(v=BTS.10).aspx

最后,请允许我说:请不要像您在代码中所做的那样处理异常。您不应该捕获异常只是为了再次抛出它。这是一种非常糟糕的编程实践,它会损害性能,还会导致您丢失异常的原始堆栈跟踪,从而使诊断和解决任何问题变得更加困难。请参阅http://winterdom.com/2002/09/rethroingexceptionsinc

I'm not sure what the actual question here is.... are you talking about how to catch the exception in the orchestration? How to make it go into the ESB Exception Handling system or what?

To handle an exception in an orchestration you need to use a Scope shape (where you put in the code/shapes that can throw the exception) and then add a Exception handler to it (kinda like a try/catch block).

For the ESB stuff, see here: http://msdn.microsoft.com/en-US/library/ee250235(v=BTS.10).aspx

Finally, allow me to say: Please do NOT handle exceptions as you're doing in your code already. You should NOT catch a exception just to throw it again. It's a very poor programming practice, it hurts performance and it will also cause you to lose the original stack trace of the exception, making it harder to diagnose and solve any issues. See http://winterdom.com/2002/09/rethrowingexceptionsinc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文