开发者

JavaScript Exceptions

How to log the Java开发者_开发百科Script exceptions? Yes I am using Try catch() block in JavaScript. I need to write all the exceptions in a text file.


You can not use javascript to read/create files because of possible security issues that could come up. You may use dumb IE and use File System Object though but this is not recommended at all.

What you could do:

Once you have logged your messages, you can use ajax to send that info to some server-side script and there from store your messages in the file you can create aferwards.


JavaScript is executed in the client side so writing to a text file is not an ideal solution.One solution is to use AJAX to log the errors in your server.

This post talks about a similar solution.


You cannot do read/write operation only using javascript. You will need to use Server side programming language for this.


Ask yourself why you are logging. For what purpose?

Logging can only take you so far. This is especially true for client Apps.

Client apps need to gracefully fail and restore themselves... that's it. You can use clever things like retries, saving state, or just a simple "opps, something's gone wrong, refresh this page"

Remember, you should be using gracefully failing Javascript, meaning the js can fail, and the app will still work with postback to the server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜