I finally have written a JavaScript HRESULT error display function that I like. It gets around JavaScript's lack of unsigned integers by just chopping off the severity and putting an "0x80" before the hex value of the facility and scode.
function show_error(e) {
var msg = "";
var errnum = (e.number & 268435455); // get rid of severity
var facility = errnum >> 16;
var scode = e.number & 65535;
msg += " number: " + e.number + " (" + translate_errnum(errnum) + ")\n";;
msg += "facility: " + translate_facility(facility) + "\n";
msg += " scode: " + scode + "\n";
msg += " msg: " + e.description + "\n";
return msg;
}
function translate_errnum(num) {
var msg = "" + num.toString(16).toUpperCase();
while (msg.length < 6) {
msg = "0" + msg;
}
return "0x80" + msg;
}
function translate_facility(num) {
switch (num) {
case 0: return "FACILITY_NULL";
case 1: return "FACILITY_RPC";
case 2: return "FACILITY_DISPATCH";
case 3: return "FACILITY_STORAGE";
case 4: return "FACILITY_ITF";
case 7: return "FACILITY_WIN32";
case 8: return "FACILITY_WINDOWS";
case 9: return "FACILITY_SECURITY";
case 10: return "FACILITY_CONTROL";
case 11: return "FACILITY_CERT";
case 12: return "FACILITY_INTERNET";
case 13: return "FACILITY_MEDIASERVER";
case 14: return "FACILITY_MSMQ";
case 15: return "FACILITY_SETUPAPI";
case 16: return "FACILITY_SCARD";
case 17: return "FACILITY_COMPLUS";
case 18: return "FACILITY_AAF";
case 19: return "FACILITY_URT";
case 20: return "FACILITY_ACS";
case 21: return "FACILITY_DPLAY";
case 22: return "FACILITY_UMI";
case 23: return "FACILITY_SXS";
case 24: return "FACILITY_WINDOWS_CE";
case 25: return "FACILITY_HTTP";
case 32: return "FACILITY_BACKGROUNDCOPY";
case 33: return "FACILITY_CONFIGURATION";
}
return "unknown:"+num;
}
It displays errors like this:
number: -2146828235 (0x800A0035)
facility: FACILITY_CONTROL
scode: 53
msg: File not found
In ASP pages, I use it like this:
catch (e) {
Response.Write("<pre>" + show_error(e) + "</pre>");
}
2:28:36 PM
|