The QuickBooks Online .NET SDK uses the fault types supported by the QuickBooks Online APIs to return the specific exceptions in the Intuit web responses. The SDK supports the following fault types:
The flow in which the SDK handles exceptions is as follows:
The following are the code samples that show how to implement exception handling for different fault types. For instructions on creating a DataService object, see Data Services API.
The ValidationException class handles Validation errors. The following example code shows how to handle a Validation error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | try { // Include the service call code here. The following code is for an add operation. Customer resultCustomer = service.Add(customer) as Customer; } catch (ValidationException exception) { // Include the logic for how you want your app to handle the exception. This code writes a fault messages to a console. Console.WriteLine("Message:{0}, ErrorCode:{1}", exception.Message, exception.ErrorCode); foreach (IdsError idsError in exception.InnerExceptions) { Console.WriteLine("ErrorCode:{0}, Message:{1}, Element:{2}, Detail:{3}", idsError.ErrorCode, idsError.Message, idsError.Element, idsError.Detail); } } |
The ServiceException class handles Service errors. The following example code shows how to handle a Service error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | try { // Include the service call code here. The following code is for an add operation. Customer resultCustomer = service.Add(customer) as Customer; } catch (ServiceException exception) { // Include the logic for how you want your app to handle the exception. This code writes a fault messages to a console. Console.WriteLine("Message:{0}, ErrorCode:{1}", exception.Message, exception.ErrorCode); foreach (IdsError idsError in exception.InnerExceptions) { Console.WriteLine("ErrorCode:{0}, Message:{1}, Element:{2}, Detail:{3}", idsError.ErrorCode, idsError.Message, idsError.Element, idsError.Detail); } } |
The SecurityException class handles Authentication and Authorization errors. The following example code shows how to handle an Authentication or Authorization error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | try { // Include the service call code here. The following code is for an add operation. Customer resultCustomer = service.Add(customer) as Customer; } catch (SecurityException exception) { // Include the logic for how you want your app to handle the exception. This code writes a fault messages to a console. Console.WriteLine("Message:{0}, ErrorCode:{1}", exception.Message, exception.ErrorCode); foreach (IdsError idsError in exception.InnerExceptions) { Console.WriteLine("ErrorCode:{0}, Message:{1}, Element:{2}, Detail:{3}", idsError.ErrorCode, idsError.Message, idsError.Element, idsError.Detail); } } |
The IdsException class handles Authentication and Authorization errors. The following example code shows how to handle an Authentication or Authorization error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | try { // Include the service call code here. The following code is for an add operation. Customer resultCustomer = service.Add(customer) as Customer; } catch (IdsException exception) { // Include the logic for how you want your app to handle the exception. This code writes a fault messages to a console. Console.WriteLine("Message:{0}, ErrorCode:{1}", exception.Message, exception.ErrorCode); foreach (IdsError idsError in exception.InnerExceptions) { Console.WriteLine("ErrorCode:{0}, Message:{1}, Element:{2}, Detail:{3}", idsError.ErrorCode, idsError.Message, idsError.Element, idsError.Detail); } } |