Message-ID: <816949437.15865.1614958506346.JavaMail.confluence@wiki> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_15864_246815658.1614958506345" ------=_Part_15864_246815658.1614958506345 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Handling errors - Java

Handling errors - Java

=20
=20
=20
=20

 

=20
=20
=20
=20
=20
=20

It is always possible for your request to return an error. If an error o= ccurs, e.g. if your API username/password is incorrect, our wrapper will th= row a Java exception. If you're not familiar with handling exceptions in Ja= va, it basically means you need to put the wrapper function calls in a try-= catch block as shown in the code example from here.

=20
=20
=20
=20
=20
=20
Example
=20
try {
=09Hashtable<String, String> result;
=09result =3D tmClient.sendSMS("My message", "447000000000&q=
uot;, "Sender", 72, "", "", null);
} catch(RestClientException e) {
=09Hashtable<String, String> errors =3D tmClient.getLastErrors();
}
=20
=20
=20
=20
=20
=20
=20

You must decide how to handle errors according to the logic of your part= icular application.
For example, if you're building a web interface t= o send text messages, and a send fails, you may wish to show a visual alert= to the user.
Note that more than one error can be reported at once. = Therefore although a single Java exception (the first of the errors) is thr= own, the complete set of errors encountered is available in an Hashtable of= key-value pairs. The key of each pair is the error code and the value is a= detailed description of the error. This is why the example displays the er= rors using the following code:

=20
=20
=20
=20
=20
=20
=20
for(Map.Entry<String, String> error: errors.entrySet())
=09System.out.println("Error code " + error.getKey() + ": &q=
uot; + error.getValue());
=20
=20
=20
=20
=20
=20 =20
=20
=20
=20

 

=20
=20
=20
=20

 

=20
=20
=20
=20
=20
=20
=20

You must know!

=20 =20

Our example code is an illustra= tion of how you might integrate with our systems and is not certified for p= roduction environments. You are responsible for testing and QA.

=20
=20
=20
=20
=20
------=_Part_15864_246815658.1614958506345--