/** Licensed Materials - Property of IBM IBM Cognos Products: DOCS (C) Copyright IBM Corp. 2005, 2007 US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ using System; using System.Web.Services.Protocols; using System.Xml; using System.Text; namespace Exceptions { /// /// Simple exception object for use with IBM Cognos. /// public class CognosException { private SoapException _exception = null; /// /// Create a CognosException object. /// /// A SoapException thrown by an IBM Cognos method call. public CognosException( SoapException ex ) { _exception = ex; } /// /// Return the exception message. /// public string Message { get { return _exception.Message; } } /// /// Return the exception severity. /// public string Severity { get { return _exception.Detail.SelectSingleNode( "//severity" ).InnerText; } } /// /// Return the exception errorCode. /// public string ErrorCode { get { return _exception.Detail.SelectSingleNode( "//errorCode" ).InnerText; } } /// /// Return the exception messageStrings. /// public string[] Details { get { XmlNodeList nodes = _exception.Detail.SelectNodes( "//messageString" ); string[] retval = new string[nodes.Count]; for( int idx = 0; idx < nodes.Count; idx++ ) { retval[idx] = nodes[idx].InnerText; } return retval; } } /// /// Convert this CognosException into a string for printing. /// /// A string representation of the CognosException. public override string ToString() { StringBuilder str = new StringBuilder(); str.AppendFormat( "Message: {0}\n", Message ); 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(); } /// /// Convert a SoapException into a CognosException string. /// /// This is the same as creating a CognosException and calling /// its ToString() method. /// /// The SoapException to format. /// A string representation. static public string ConvertToString( SoapException ex ) { CognosException exception = new CognosException( ex ); return exception.ToString(); } } }