Handling an IBM® Cognos® biBusHeader Exception (C# .NET)

The following code shows you how to extract the CAM element of the bibus » biBusHeader class. To see this code in context, view the C# sample SamplesCommon\SamplesHeaderExceptionHelper.cs:

 
 
using  System; 
using  System.Text; 
using  cognosdotnet_2_0; 
 
namespace  SamplesCommon 
{ 
	///  <summary> 
	///  Extract  the  interesting  bits  from  a  biBusHeader  after  a  biBusHeader 
	///  fault. 
	///  </summary> 
	public  class  HeaderExceptionHelper 
	{ 
		private  CAMException  _exception  =  null; 
 
		///  <summary> 
		///  Create  a  HeaderExceptionHelper  object. 
		///  </summary> 
		///  <param  name="crn">The  contentManagerService1  object  in  use   
		///      during  the  last  exception.</param> 
		public  HeaderExceptionHelper(  contentManagerService1  cmService  ) 
		{ 
			//  Pull  the  CAM  exception  out  of  the  biBusHeader. 
			_exception  =  cmService.biBusHeaderValue.CAM.exception; 
		} 
 
		///  <summary> 
		///  Get  the  Severity  string  from  this  biBusHeader  exception. 
		///  </summary> 
		public  string  Severity  { 
			get  { 
				return  _exception.severity.ToString(); 
			} 
		} 
 
		///  <summary> 
		///  Get  the  errorCode  string  from  this  biBusHeader  exception. 
		///  </summary> 
		public  string  ErrorCode  { 
			get  { 
				return  _exception.errorCodeString; 
			} 
		} 
 
		///  <summary> 
		///  Get  the  details  (messageString)  from  this  biBusHeader  exception. 
		///  </summary> 
		public  string[]  Details  { 
			get  { 
				string[]  retval  =  new  string[_exception.messages.Length]; 
 
				for(  int  idx  =  0;  idx  <  _exception.messages.Length;  idx++  )  { 
					retval[idx]  =  _exception.messages[idx].messageString; 
				} 
 
				return  retval; 
			} 
		} 
 
		///  <summary> 
		///  Get  the  promptInfo  (and  useful  captions/displayObjects  inside)  to   
		///  facilitate  prompting  the  user,  if  this  is  a  recoverable  exception. 
		///  </summary> 
		public  promptInfo  PromptInfo  { 
			get  { 
				return  _exception.promptInfo; 
			} 
		} 
 
		///  <summary> 
		///  Convert  this  biBusHeader  exception  into  a  string  for  printing. 
		///  </summary> 
		///  <returns>A  string  representation  of  the  biBusHeader  exception.</returns> 
		public  override  string  ToString()  { 
			StringBuilder  str  =  new  StringBuilder(); 
			 
			str.AppendFormat(  "Severity:    {0}\n",  Severity  ); 
			str.AppendFormat(  "ErrorCode:  {0}\n",  ErrorCode  ); 
			str.AppendFormat(  "Details:\n"  ); 
			foreach(  string  s  in  Details  )  { 
				str.AppendFormat(  "\t{0}\n",  s  ); 
			} 
 
			return  str.ToString(); 
		} 
 
		///  <summary> 
		///  Convert  a  biBusHeader  exception  into  a  string. 
		///   
		///  This  is  the  same  as  creating  a  HeaderExceptionHelper  and  calling 
		///  its  ToString()  method. 
		///  </summary> 
		///  <param  name="ex">The  Service  object  that  threw  the  exception.</param> 
		///  <returns>A  string  representation  of  the  biBusHeader  exception.</returns> 
		static  public  string  ConvertToString(  contentManagerService1  cmService  )  { 
			HeaderExceptionHelper  exception  =  new  HeaderExceptionHelper(  cmService  ); 
 
			return  exception.ToString(); 
		} 
	} 
}