ASP.NET catch引用脚本文件异常 [英] ASP.NET catch referenced script file exceptions

查看:97
本文介绍了ASP.NET catch引用脚本文件异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何捕获由aspx页面引用的JavaScript文件引发的异常?

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

推荐答案

您无法捕获来自Web服务器的用户浏览器发生异常。这不是由于某些ASP.NET限制,只是在客户端上执行的代码(javascript)与在数千英里外的服务器上执行的代码无关。如果你想抓住并处理一个JavaScript异常,你应该使用javascript的try ... catch机制

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

你想做什么?您是否在跟踪代码中的错误?如果客户端的浏览器无法处理您的JavaScript,是否要收到通知?还是要通知服务器客户端出现问题?

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?

编辑您真正寻找的是JavaScript的日志框架。在那里有多个日志记录框架,其中一些支持通过Ajax日志记录到远程服务器,例如。 log4javascript log4js

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 .

这篇关于ASP.NET catch引用脚本文件异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆