A variation of error swallowing is to display a generic error for anything that goes wrong:
Now the problem is that the error is so generic as to be of no benefit for the client or developer.
Use Error Types to Create More Meaningful Messages
- Occurs within the
- Occurs when a numeric variable or parameter is outside of its valid range.
- Occurs when de-referencing an invalid reference.
- Occurs while parsing code.
- Occurs when a variable or parameter is not of a valid type.
- Occurs when
decodeURI()are passed invalid parameters.
constructor: Specifies the function that created an instance's prototype.
message: Error message.
name: One of the six Error classes outlined above, or simply "Error".
description: Error description. Similar to message.
number: Error number.
fileName: Path to file that raised this error.
lineNumber: Line number in file that raised this error.
stack: Stack trace.
The following code creates a customized error message using a combination of error properties:
Throwing Your Own Errors
throw statement gives you the ability to create custom exceptions
in order to generate even more specific and detailed error messages. In
addition to Errors, the throw statement works with strings, integers, booleans
or just about any object type. Here's a function that validates an age against
minimum and maximum values and throws an appropriate error if it fails.
Regardless of the results, it always returns success or failure:
Adding Custom Properties to Your Errors
Having the ability to throw objects gives us the advantage of being able
to define our own properties and methods. In this example, the error is
really an object literal. It would be easy to imagine how the error handling
code could use the
htmlMessage to insert a link in the document using the
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. Rob's latest, entitled KNIGHTFALL, was a collaboration between himself, the former Ivory Knight vocalist, and legendary guitarist/producer, Jeff Waters of Annihilator fame. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: April 27, 2009