Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I do this all the time for windows forms, and I put this code into the code behind for web forms and I get no errors, but it doesnt work, is there a way to do a try catch for asp.net web forms? I use vb.net code behind, thanks!

 

Try

Cmd.ExecuteNonQuery()

Catch ex As Exception

MsgBox("Error: " & ex.message)

End Try

Posted

Hey,

 

Try the following:

 

Catch ex As Exception

Dim strErrorMessage As String

strErrorMessage = ex.Message.ToCharArray

strErrorMessage = strErrorMessage.Replace(Chr(13), "\n")

strErrorMessage = trErrorMessage.Replace(Chr(10), "\n")

strErrorMessage = trErrorMessage.Replace("'", " ")

strErrorMessage = trErrorMessage.Replace("""", " ")

 

Response.Write("<script language='JavaScript'>")

Response.Write("alert('" & trErrorMessage & "');")

Response.Write("</script>")

End Try

 

The "Replace" statements take away any carriage returns, single, and double quotes that come within the Message property of the Exception, and that might make the JavaScript code to fail.

 

Hope this helps.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...