3

Error messages returned from SendMessage occasionally have useful information in them. For example:

SendMessage["Twitter", StringJoin@ConstantArray["a", 141]]

returns:

ServiceExecute::apierr: The service returned the following error message: {{code->186,message->Status is over 140 characters.}}.

Based on the docs for $MessageList, I assumed I could add err = $MessageList to the same cell as the SendMessage to capture the message; however err is an empty list when I do so.* Additionally, when I call MessageList[n] where n is the appropriate cell number, I get the name of the message {ServiceExecute::apierr} but not the details.

How can I go about accessing the details of the error message in this case? Another similar question has been asked; however, it's not clear to me how the answers there apply in this case. (And for completeness, another good read.)


* Executing Plot[];err=$MessageList does populate err, but I don't know why SendMessage does not behave in the same fashion.
bobthechemist
  • 19,693
  • 4
  • 52
  • 138
  • What exactly is the problem with the answer in your first link? It will collect complete message information. – Szabolcs Nov 16 '14 at 17:31
  • @Szabolcs your answer is very helpful, but I am struggling with how to implement it efficiently in my case. If I am only concerned with errors from this one function call, is my solution to create a module that (a) initializes messages; (b) defines collectMessages (c) calls AddHandler (d) calls SendMessage and (e) calls RemoveHandler? Or, would I initialize collectMessages and then clear messages before trying to send the tweet? I'm concerned about overhead since, ultimately, this program is being run from an RPi, making efficiency a high priority. – bobthechemist Nov 17 '14 at 02:01
  • As a complete aside, running @Szabolcs's code gives me (for messages[[1]]): Hold[Message[ToExpression::sntx, "Twitter", "Privatezztop$3...` Excuse me while I find my dark sunglasses... – bobthechemist Nov 17 '14 at 02:03
  • I added another answer in the linked thread, which may be of use: http://mathematica.stackexchange.com/a/96390/12 – Szabolcs Oct 07 '15 at 10:52

0 Answers0