URIError
constructor
In JavaScript you create a URIError
instance using the constructor URIError
.
Description
Creates a URIError
object when URI handling functions are passed malformed URIs.
Syntax
Signature | Description |
---|---|
anError = new URIError([message]); | In JavaScript you create a range error instance using the constructor URIError . |
Parameters
Parameter | Description |
---|---|
message | An optional description of the error. |
Class Properties
Class Property | Description |
---|---|
prototype | Enables property assignment to objects of type URIError . |
Instance Properties
Instance Property | Description |
---|---|
constructor | Returns a reference to the URIError function that created the prototype. |
name | An error name. |
Class Methods
None.
Instance Methods
None.
Examples
Let's look at some examples of throwing a uri error within our code.
// Throw an error.
try {
throw new URIError();
} catch (e) {
alert('A uri error: ' + e.name);
}
// Throw an error with a message.
try {
throw new URIError('Throwing a uri error.');
} catch (e) {
alert('A uri error with message: ' + e.name + ': ' + e.message);
}
We can also create our own URIError
instances as the example below shows.
// Create our own URIError object.
function ourURIError(message) {
this.name = 'OurURIError';
this.message = message || 'Default Message Used When No Message Passed';
}
// Inherit from the URIError prototype.
ourURIError.prototype = new URIError();
ourURIError.prototype.constructor = ourURIError;
// Throw an error.
try {
throw new ourURIError();
} catch (e) {
alert('Our Error: ' + e.name + ' Message: ' + e.message);
}
// Throw an error and a message.
try {
throw new ourURIError('A Message we have passed');
} catch (e) {
alert('Our Error: ' + e.name + ' Our Message: ' + e.message);
} finally {
alert('A finally statement will always be executed!');
}
Related Tutorials
JavaScript Advanced Tutorials - Lesson 2 - Errors