Exceptions

Exceptions are thrown by a method call when the Topics service detects a user error or an internal error.

Topics service methods may throw the following exceptions:

  • InvalidArgumentException—Thrown for internal errors if you define invalid information in a field or argument. One example is passing a TopicsServiceContext argument with a value of null. Another example is requesting actions for a topic ID of -5. Topic IDs must be a number greater than or equal to 0.
  • TopicsServiceException—Thrown for errors other than InvalidArgumentException. This includes user input errors. Another example is a semantic error such as getting actions contexts for a topic with an ID that does not exist, or for a topic that was deleted or closed.

These exceptions contain an errorCode field that categorizes the exception, a message field with a default message that can be displayed to the user, and a detailedMessage field for logging and diagnostics.

You can either display the default message or create a customized message for a particular error code. For example, if there is a missing topic name for a new topic, the customized message could be The new topic name is required instead of the default message You must enter a new topic name.

Method call when the Topics service detects a user error or an internal error: