Charles Young

  Home  |   Contact  |   Syndication    |   Login
  140 Posts | 54 Stories | 357 Comments | 376 Trackbacks

News

MVP - Microsoft Most Valuable Professional

Twitter












Article Categories

Archives

Post Categories

Image Galleries

Alternative Feeds

BizTalk Bloggers

BizTalk Sites

CEP Bloggers

CMS Bloggers

Fun

Other Bloggers

Rules Bloggers

SharePoint Bloggers

Utilities

WF Bloggers

A quick tip.  The Throw shape in BizTalk can cause a little initial confusion.  The shape has an 'Exception Object' property which you assign using a drop-down list.   When you first drag the shape onto your Orchestration, the only item in the list is 'General Exception'.  Intuitively, you might expect that you can select an exception class, in a similar fashion to setting the 'Exception Object' property of a Catch Exception block.   However, this is not the case.   If you wish to throw a specific exception, you will need first to create a variable of an exception type (or use the exception object defined in a Catch Exception block).   This variable will then be displayed in the drop-down list of the 'Exception Object' property.  There is no need to write code to instantiate the object, as it will be automatically instantiated.   However, you may wish to include expression code to set property values.

You can only use 'General Exception' if the Throw statement is placed in a Catch Exception block - i.e., you are rethrowing an exception.  I did some testing, and it appears that this is essentially the meaning of setting 'General Exception' on a Throw shape.  It rethrows the existing exception object, as is.  The exception is raised by calling an inherited method of the BizTalk Context class.  

When catching exceptions, choosing 'General Exception' as the Exception Object allows Catch Exception blocks to handle exceptions which are not derived from System.Exception. The .NET framework allows any class to be raised as an exception, but some .NET languages such as C# impose a tighter restriction that exceptions must be System.Exception classes.   'General Exception' allows BizTalk to deal with any exception it may catch (and rethrow) from an external .NET component, regardless of the language that component was written in.

posted on Monday, April 26, 2004 10:24 AM

Feedback

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 4/26/2004 10:44 AM Jan
Charles,

Suppose you have a Scope shape with an Exception Handler block which catches a General Exception. As you described in your post, this will catch all exceptions that can happen in the Scope. The downside of using the General Exception is that you don't know what went wrong, there is no exception object, so you can get a hold of the error message. So what I would like to do is to use a General Exception handler, but inside the catch block I want to be able to get the error message. Any ideas how to do that?

Jan

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 4/26/2004 10:51 AM Charles Young
A good point. I don't believe you can do this because BizTalk does not expose the object to your XLANG code. Indeed, from what I have seen, the exception object, in this case, is kept at arms length from the Orchestration code. I think the idea is to avoid catching a 'General Exception' unless you really need to. I would just use System.Exception or a derived class, as this will always work if you are using external C# code (and VB.NET code as well, I believe).

Throwing a 'General Exception' is a different matter. BizTalk just throws the existing exception object, which you can then catch using an explicit exception handler in the normal way.

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 4/26/2004 2:27 PM Jan
Sure the System.Exception would suffice for C# or VB.NET exceptions. But when thing really go wrong BizTalk throws an exception that's not inherited from the System.Exception class so the catch won't catch it. :-)

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 4/26/2004 2:53 PM Charles Young
Is this behaviour that you have seen? I.e., Does the BTS engine throw non-System.Exception objects? Or is this just 'hypothetical'. I haven't coded with C++ managed extensions, for example, but I suspect you could probably throw a non-System.Exception from a C++ component.

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 2/8/2005 12:34 AM Mike
Hi! Thanks for explaining that - MS certainly needs to explain it better.

You wrote:
"There is no need to write code to instantiate the object, as it will be automatically instantiated. However, you may wish to include expression code to set property values."

I am trying to throw a System.Exception and set the message property for it. If I instantiate it myself (exException = new System.Exception("My error message");) , I get a 'illegal name-hiding' error.
If I let the Throw shape do the instantiation, I don't see how I can set the message property. Any ideas?

Thanks for your help.

Mike

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 3/9/2005 10:58 AM Peter
You probably already have a solution to your problem but anyway.. I just ran into the 'illegal name-hiding' problem myself when catching a system.Exception in an orchestration. The Property "Exception Object Name" was set to the same name as my Exception variable. Changing that name to something else and refering to the new name in the catch expression solved the problem.

# Handling Exceptions within an Orchestration 11/4/2005 12:13 PM { dispatches }
BizTalk Server 2004 allows you to catch an exception within an orchestration through the Scope shape....

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 9/10/2006 11:31 PM Daniel Toomey
In BTS 2006, I am trying to throw a System.Exception with a specific message. However, when I try to assign the message property, I get an error: "Cannot modify a readonly or literal field." Also, the message variable does not appear as an Exception Obejct type in my Throw Exception shape. Any ideas?

# re: The BizTalk Server 2004 Throw shape and 'General Exception' 12/27/2008 11:32 PM savaş oyunu
Sure the System.Exception would suffice for C# or VB.NET exceptions. But when thing really go wrong BizTalk throws an exception that's not inherited from the System.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: