I'm using jQuery to handle all my ajax needs for an ASP.NET site coded in VB. When I use the built in $.ajax function to POST to a code-behind function and there is an exception, it simply exits the function, and shows an error on the client side.
Besides making debugging difficult when coding, the bigger issue is that the Application_Error function in Global.asax isn't firing when those exceptions occur. This is making it almost impossible to track production errors.
Why would it not bubble up to Application_Error? Is the answer to wrap the code-behind function in a Catch statement?
jQuery ajax function:
$.ajax({
type: "POST",
url: "page.aspx/GetData",
data: "{'param':'" + param_value + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
processData(msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus + " - " + errorThrown);
}
});
VB.NET function:
<Script.Services.ScriptMethod()> _
<WebMethod()> _
Public Shared Function GetData(ByVal param As Integer) As String
'Parse some data
Return data
End Function