Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top