John Sands' Radio Weblog :
Updated: 9/19/2002; 12:08:17 PM.

 

 
 

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Tuesday, March 19, 2002

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    


© Copyright 2002 John Sands.



Click here to visit the Radio UserLand website.

 


March 2002
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Feb   Apr

PicoSearch
blogchalk: John/Male/46-50. Lives in United States/Palm Bay/Lockmar and speaks English. Spends 80% of daytime online. Uses a Faster (1M+) connection.