There is good explanation available for error handling on this and similar links. Here there is information on handling inappropriate input arguments and handling unprocessed functions using $Failed. But it is much of incomplete because I want to catch error message and according to that display some specific message. For example if I get
Integrate::idiv: Integral of E^n does not converge on {1,\[Infinity]}. >>
Than I want to display some specific message in words which is possible if I can capture this message and extract from it or if Mathematica returns some error code associated.
Is there some better technique available than just using $Failed everywhere ?
Internal`AddHandler["Message", . . .]may be exactly what you're looking for. – Mr.Wizard Jul 27 '13 at 14:33Throwto find out which error it was. No time right now do decribe this in more detail, but it is a logical extension of the exception-based method I described in the link you cited. You can also look at the source code ofRLinkto see this applied in practice. – Leonid Shifrin Jul 28 '13 at 12:09