Handling VCard Errors - george-haddad/cardme GitHub Wiki

Table of Contents

The Basics

The basic idea behind CardMe's error handling interface VCardErrorHandling is to catch any VCard related errors in one place so that they may be reviewed and handled (either automatically or manually). The VCardEngine and VCardWriter are aware if the VCard supports this interface or not. VCard errors occur when parsing a VCard and when writing a VCard.

Exceptions

There are 2 main type of exceptions used in CardMe

  • VCardException: Thrown when there is a serious error that will most likely prevent CardMe from continuing further
  • VCardBuildException: Thrown when there is a parsing or writing error. Usually these errors are caught, logged and CardMe continues to work

To Throw or Not to Throw

When a VCard implements the VCardErrorHandling interface there is an option to throw exceptions or not. When flagging a VCard to throw exceptions it means that any exception that occurs (fatal or minor) will cause the reading or writing process to terminate. If flagged to not throw exceptions then all exceptions are caught and logged into the VCard object. These exceptions can been access through the getErrors() method. Though don't be fooled, a VCard exception can be thrown by the VCardEngine or VCardWriter it self if an error occurs (concerning a VCard) and it can not move forwards.

Other exceptions such as your average IOException, NullPointerException and the rest are set to be thrown in case of errors not relating to VCards.

Viewing VCard Errors

Errors in VCards can be viewed by accessing the getErrors() method. This returns a List of VCardError objects. These objects contain:

  • Error Message
  • Throwable that was caught
  • Severity Rating

CardMe also provides a helper method called formatException() in the class StringUtil that will format an exception object's stack trace like you would see it in the console.

⚠️ **GitHub.com Fallback** ⚠️