views:

236

answers:

1

Hello

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 doesnt exists the inside class catch the exception but dont 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 orchstration and expect to catch the exception in my orchstration after the class and the emthod gets it

A: 

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

tomasr
Thank you for the replyI did catch the exception in order to see it in debug so thats why you see this code.the issue is that the exception occures in the class (second code link) and the orch doesnt catch it (after the method should catch it)but if i throw an error in the method then the orch catch it and handle itI do use ascope in the orchstration and build the excption handling by the book (this system is in production alredady and working perfect except for this error so far)Thanks
IB