Source: ManagedError.js

/**
 * ManagedError.js
 *
 * Created by Matthias Seemann on 8.01.2013.
 * Copyright (c) 2013 Visisoft GbR. All rights reserved.
 */

define(['api/errorCodes', 'lib/Object'], function(ErrorCodes, Inheritance)
	{
		/// check whether to subclass Error in IE or others

		var ieError = new Error(7, "test");

		/**
		 * Error class used by the API in exceptions and callbacks
		 * @class ManagedError
		 * @memberof LiveSupport
		 * @param {number} [code=ErrorCode.GeneralError] an error code
		 * @param {string} [message=""] an error description
		 * @constructor
		 * @extends Error
		 * @property {LiveSupport.VisitorAPI.ErrorCode} number The numeric error code.
		 * @property {string} message The description of the error.
		 */
		var ManagedError = function(code, message)
		{
			switch (arguments.length)
			{
				case 0:
					code = ErrorCodes.GeneralError;
					message = "";

					break;
				case 1:
					if (typeof code == "string")
					{
						message = arguments[0];
						code = ErrorCodes.GeneralError;
					}
					else if (typeof code != "number")
					{
						code = ErrorCodes.GeneralError;
						message = "";
					}

					break;
				default:
					if (typeof code != "number")
					{
						code = ErrorCodes.GeneralError;
					}

					if (typeof message != "string")
					{
						message = "";
					}
			}

			/// use prototypal inheritance to inherit from built-in Error class ///
			/// return custom object from constructor

			var error;

			if (typeof ieError.number == "undefined")
			{
				/// non IE error
				error = Inheritance.createInstanceWithPrototype(new Error(message));

				error.number = code;
			}
			else
			{
				/// IE error
				error = Inheritance.createInstanceWithPrototype(new Error(code, message));
			}

			return error;
		};

		return ManagedError;
	}
);