nsIIOService.newURI (...) is what you are looking for. It outputs NS_ERROR_MALFORMED_URI if the URI string is invalid.
Example:
try { var ioServ = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var uriObj = ioServ.newURI(uriString, uriCharset, baseURI); } catch (e) {
source share