I think its a great way to bubble up that bit more information about what caused the error to the developer (and any error logging you may be doing as well) & help you work out what has happened, so thought I would share it:
1: try
2: {
3:
4: //do something here that tries to use the CRM Webservice
5:
6: }
7:
8: catch (SoapException ex)
9: {
10:
11: string errorMessage = ex.Message;
12:
13: if (ex.Detail != null)
14: {
15:
16: // If there is a InnerText message then we will overwrite with this instead. It can be
17:
18: // more helpful to explain the error.
19:
20: errorMessage = ((System.Xml.XmlElement)ex.Detail).InnerText;
21:
22: }
23:
24: throw new Exception("Something went wrong when communication with the Web Service. Error: " + errorMessage);
25:
26: }
No comments:
Post a Comment