0

How to catch exceptions raised by a referenced javascript file in an aspx page??

2
  • Is it the famed debug .js file? Are you using the Script Manager? Ajax toolkit? More details please. Commented Jul 7, 2010 at 10:47
  • Are you using an Update Panel? Commented Jul 7, 2010 at 10:48

2 Answers 2

3

You can't catch an exception that occurs on the user's browser from the web server. This is not due to some ASP.NET limitation, it's just that the code (javascript) that executes on the client has nothing to do with the code that executes on the server, probably thousands of miles away. If you want to catch and handle a javascript exception you should use javascript's try...catch mechanism

What are you trying to do? Are you trying to trace bugs in your code? Do you want to be notified if a client's browser can't handle your javascript? Or do you want to notify the server that something went wrong in the client?

EDIT What you are really looking for is a logging framework for javascript. There are multiple logging frameworks out there, some of which support logging to a remote server through Ajax, e.g. log4javascript and log4js .

Sign up to request clarification or add additional context in comments.

4 Comments

Actually, I want to catch the exception at client side and store it in server using Ajax for future improvements.
What you are looking for is logging for Javascript.
Depends on what you wanted to log, you can use framework or DIY
When the question is "how can I do it", the DIY answer is not the best. Besides, there is always DRY
0

Maybe you want to this.

<head runat="server">
    <title></title>
    <script type="text/javascript" src="JScript.js"></script>
</head>
<body>
  <form id="form1" runat="server">
      <button type="button" onclick="try{ testException();} catch(e){alert(e);}">Test Exception</button>
   </form>
</body>

JScript.js

function testException() {
    e.data = 10;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.