# How to store error message from a command into a variable [duplicate]

I am inserting data into server using SQLInsert. I want to store the error messages i encounter when data is not inserted. Apparently the error output is different from function output how do i store the error output rather than the function output $Failed. • Are $MessageList or MessageList any use to you? – aardvark2012 Jun 29 '17 at 10:53
• The complete error is: JDBC::error: Conversion failed when converting date and/or time from character string. While MessageList[-1] produces {JDBC::error} and \$MessageList gives {}. So nope. – user13892 Jun 29 '17 at 11:36
• Question 134698 and the link it contains may be of help. – bbgodfrey Jun 29 '17 at 23:17
• You will like my this post. :) – yode Jun 30 '17 at 4:38

To make my comment above more concrete, question 134698 gives the basic process for capturing the error messages as strings. For instance, the two error messages from

NDSolve[k y[x] + (y''[x] == 0, y, x]


can be captured by

t = "MessagesText" /. EvaluationData[NDSolve[k y[x] + (y''[x] == 0, y, x]];

t
(* {"NDSolve::ndlim : Range specification x is not of the form {x, xend} or
{x, xmin, xmax}.",
"NDSolve::ndnco : The number of constraints (0) (initial conditions) is not equal to
the total differential order of the system plus the number of discrete
variables (2)."} *)

• Thank you, it works for my case as well. – user13892 Jun 30 '17 at 6:56