Geeks With Blogs
BizTalk Blog by Chris Han System Design for Enterprise Agility,

I got this error myself when I try to design my own exception handlling strategy in the orchestration.

The BizTalk 2006 document is better. There is a “caution” section says: 

Do not select GeneralException in the Throw Exception shape. This type should only be used for rethrowing exceptions in a Catch Exception block.

The error I got is because I'm trying to do a quick and dirty test with a GeneralException.

What should you do? It's simple.

  1. Create a variable.
  2. Give it a .NET type System.Exception. (You should find it in mscorlib assembly)
  3. Assign this variable to your Throw Exception's Exception Object property.
  4. Enjoy it.
Posted on Thursday, March 2, 2006 8:58 AM BizTalk | Back to top


Comments on this post: Throw a customer exception may get an error: May only rethrow in a catch block

# re: Throw a customer exception may get an error: May only rethrow in a catch block
Requesting Gravatar...
Hi I saw your post: The provided code is also simple to use from an Expression Shape and provides a way to throw custom exception of any type with any error message

/// <summary>
/// Provides a way to throw custom exceptions (Targeted for use from BizTalk solutions)
/// </summary>
/// <param name="errorMessage">The Message part of the exception</param>
public static void ThrowException(string errorMessage)
{
throw new Exception(errorMessage);
}
/// <summary>
/// Provides a way to throw any custom exception type (Targeted for use from BizTalk solutions)
/// </summary>
/// <param name="errorMessage">The error message to throw</param>
/// <param name="t">The type of the Exception to throw. Example: typeof(System.ArgumentException)</param>
public static void ThrowException(string errorMessage, Type t)
{
System.Reflection.Assembly excAssembly = t.Assembly;
Object[] args = new Object[1] { errorMessage };
Exception e =(Exception) excAssembly.CreateInstance(t.FullName, false, System.Reflection.BindingFlags.CreateInstance, null, args, null, null);
throw (e);
}
Left by Michael on Jan 12, 2007 3:52 AM

# re: Throw a customer exception may get an error: May only rethrow in a catch block
Requesting Gravatar...
this info saved me from banging my head on the wall.

question: can you expound on step #4? ;-)
Left by Dexter Legaspi on Mar 05, 2009 9:07 AM

# re: Throw a customer exception may get an error: May only rethrow in a catch block
Requesting Gravatar...
thx Chris

btw: Do they burn all BiztTalk developers at Microsoft like witches? If not, I bring the matches and a can of gasoline !
Left by Volarus on Nov 09, 2009 7:53 AM

Your comment:
 (will show your gravatar)


Copyright © Chris Han | Powered by: GeeksWithBlogs.net