How to get Exception messages without the call stack

Viewed 15255

I need to get only the exception message without the call stack or any other string.

I thought that using Exception.Message would be enough, but it keeps giving me the message mixed with the call stack. Do you know how to get rid of all the rest of information that comes with Exception.Message?

try
{

}
catch (Exception ex)
{
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "alert('" + ex.Message + "');", true); 
}

This is what I get when I use ex.Message:

System.Web.Services.Protocols.SoapException: The server can not process the request. ---> System.NullReferenceException: Object reference not set to an instance of an object in . in WebService.ProcessRequestArc.............--- End of inner exception stack trace ---

When what I only need is:

The server can not process the request

Is there any way to get only that part of the message?

4 Answers
Related