Jonathan 的个人资料Jon's Vista Gadgets Blog日志列表 工具 帮助

日志


4月24日

HOW TO: Debugging Gadgets

Debugging Gadgets can be a little frustrating, not only whilst coding; but also when trying to get useful feedback from users who've reported issues.

The simplest way to achieve this, is to log debug entries out to a file.  In the example below, we check to see if "debug.txt" exists in the Gadget folder and if it does write debugging information to it.

The first step is to see if the file exists and open it.  In the following code, we create a BOOLEAN variable "bDebug" which we can use later to output more detailed information, beyond simply errors:

var bDebug = oFSO.FileExists(gadgetPath+"\\debug.txt");
try{
if (bDebug)
  var debugLogFile = oFSO.OpenTextFile(gadgetPath+"\\debug.txt", 2);
} catch(err) {bDebug = false; debugLog("Open debug.txt error: "+err.name+" - "+err.message)}

//log a debug entry
function debugLog(str) {
    try{
        System.Debug.outputString(str);
        if (bDebug) debugLogFile.WriteLine(str);
    } catch(err) {}
}

It's good practice to get into the habit of wrapping all your functions in a try/catch loop, to prevent Runtime errors from popping up:

try{
  // your code
} catch (err) {debugLog(err.name+ " - "+err.message)}

It's also a good idea to put in tracking information, so you know where you are in the code.  For example:

if(bDebug) debugLog("Register ActiveX");
if(bDebug) debugLog("  trying HKCU");
if (!activateXDLL("HKCU")) {
    if(bDebug) debugLog("  trying HKLM");
    if (!activateDLL("HKLM"))
        debugLog("Error creating ActiveX object");
}

To enable "debug mode", simply create a blank text file in your Gadget folder called "debug.txt".

Personally, I put this code into all Gadgets and leave "debug.txt" out of the Gadget package.  When a user reports an issue, I ask them to create the file and eMail it back to me once they've reproduced the problem.

 

Whilst your developing your code, I'd also advise running Microsoft's Debug View; which will allow you to watch all debug entries as they occur.

In a future article, I'll detail how to write out debugging information from VB and C++ ActiveX DLL's.

评论 (1)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

没有名字发表:
http://www.batterylaptoppower.com/toshiba/satellite-m110.htm toshiba satellite m110 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-m115.htm toshiba satellite m115 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-m40.htm toshiba satellite m40 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-m45.htm toshiba satellite m45 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-m50.htm toshiba satellite m50 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-m55.htm toshiba satellite m55 battery ,
http://www.batterylaptoppower.com/toshiba/pa3356u.htm toshiba pa3356u battery ,
http://www.batterylaptoppower.com/toshiba/pa3420u.htm toshiba pa3420u battery ,
http://www.batterylaptoppower.com/toshiba/satellite-l10.htm toshiba satellite l10 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-l100.htm toshiba satellite l100 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-l15.htm toshiba satellite l15 battery ,
http://www.batterylaptoppower.com/toshiba/pa3395u-1brs.htm toshiba pa3395u-1brs battery ,
http://www.batterylaptoppower.com/toshiba/pa3421u-1brs.htm toshiba pa3421u-1brs battery ,
http://www.batterylaptoppower.com/toshiba/pa3465u-1brs.htm toshiba pa3465u-1brs battery ,
http://www.batterylaptoppower.com/toshiba/pabas069.htm toshiba pabas069 battery ,
http://www.batterylaptoppower.com/toshiba/pa3536u.htm toshiba pa3536u battery ,
http://www.batterylaptoppower.com/toshiba/satellite-x200.htm toshiba satellite x200 battery ,
http://www.batterylaptoppower.com/toshiba/pa3536u-1brs.htm toshiba pa3536u-1brs battery ,
http://www.batterylaptoppower.com/toshiba/satellite-p200.htm toshiba satellite p200 battery ,
http://www.batterylaptoppower.com/toshiba/satellite-p205.htm toshiba satellite p205 battery ,
http://www.batterylaptoppower.com/toshiba/pa3534u-1brs.htm toshiba pa3534u-1brs battery ,
http://www.batterylaptoppower.com/toshiba/satellite-a205.htm toshiba satellite a205 battery ,
4 月 2 日

引用通告

此日志的引用通告 URL 是:
http://vistagadgets.spaces.live.com/blog/cns!D8F26C345B42BC67!222.trak
引用此项的网络日志