Hi, We've gotten feedback from the developers that it is currently difficult to retrieve the reason field from the ApiError since in statically typed languages you must first cast the error. I think the reflection tactic you've outlined in version 2 is a good work around for this problem. If you are using the AdWords API Java client library there is currently a feature request open that you can comment on:
http://code.google.com/p/google-api-adwords-java/issues/detail?id=41 Best, - Eric Koleda, AdWords API Team On Jan 22, 8:14 am, ryo <tadaima10ji27...@gmail.com> wrote: > Hi all, > > I am wondering what exception handling using v2009 should be > implemented. > (I use Java.) > > For example, > > Version 1: > > public String getErrorReason(ApiError error) { > if (error instanceof AdError) { > // return reason. > } else if (error instanceof AdExtensionError) { > // return reason. > } else if (error instanceof AdExtensionOverrideError) { > // return reason. > } else if (AdGroupAdCountLimitExceeded) { > // return reason. > } else if (AdGroupAdError) { > // return return. > } else if ... > > snip... > > } else if (error instanceof TargetError) { > // return reason. > } > > } > > Version 2: > > public String getErrorReason(ApiError error) { > > Method method = null; > try { > method = error.getClass().getDeclaredMethod("getReason"); > } catch (SecurityException e) { > // return message > } catch (NoSuchMethodException e) { > // process the class which is not implemented 'getReason()' > } > > String errorReason = null; > try { > errorReason = (String) method.invoke(error).toString(); > } catch (IllegalArgumentException e) { > // return message > } catch (IllegalAccessException e) { > // return message > } catch (InvocationTargetException e) { > // return message > } > return error.getgetApiErrorType() + "." + errorReason; > > } > > Both Version 1 and Version 2 may by bad practice , I think... > > Do you have any good ideas? -- You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to adwords-...@googlegroups.com. To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en.