JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow URIError

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
messageAn optional description of the error.

Class Properties


Class Property Description
prototypeEnables property assignment to objects of type URIError.

Instance Properties


Instance Property Description
constructorReturns a reference to the URIError function that created the prototype.
nameAn 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);
}  


Press the button below to action the above code:


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!');
}   


Press the button below to action the above code:



Related Tutorials

JavaScript Advanced Tutorials - Lesson 2 - Errors




  


go to home page Homepage go to top of page Top