Source: Core/DeveloperError.js

  1. /*global define*/
  2. define([
  3. './defined'
  4. ], function(
  5. defined) {
  6. 'use strict';
  7. /**
  8. * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,
  9. * argument out of range, etc. This exception should only be thrown during development;
  10. * it usually indicates a bug in the calling code. This exception should never be
  11. * caught; instead the calling code should strive not to generate it.
  12. * <br /><br />
  13. * On the other hand, a {@link RuntimeError} indicates an exception that may
  14. * be thrown at runtime, e.g., out of memory, that the calling code should be prepared
  15. * to catch.
  16. *
  17. * @alias DeveloperError
  18. * @constructor
  19. * @extends Error
  20. *
  21. * @param {String} [message] The error message for this exception.
  22. *
  23. * @see RuntimeError
  24. */
  25. function DeveloperError(message) {
  26. /**
  27. * 'DeveloperError' indicating that this exception was thrown due to a developer error.
  28. * @type {String}
  29. * @readonly
  30. */
  31. this.name = 'DeveloperError';
  32. /**
  33. * The explanation for why this exception was thrown.
  34. * @type {String}
  35. * @readonly
  36. */
  37. this.message = message;
  38. //Browsers such as IE don't have a stack property until you actually throw the error.
  39. var stack;
  40. try {
  41. throw new Error();
  42. } catch (e) {
  43. stack = e.stack;
  44. }
  45. /**
  46. * The stack trace of this exception, if available.
  47. * @type {String}
  48. * @readonly
  49. */
  50. this.stack = stack;
  51. }
  52. if (defined(Object.create)) {
  53. DeveloperError.prototype = Object.create(Error.prototype);
  54. DeveloperError.prototype.constructor = DeveloperError;
  55. }
  56. DeveloperError.prototype.toString = function() {
  57. var str = this.name + ': ' + this.message;
  58. if (defined(this.stack)) {
  59. str += '\n' + this.stack.toString();
  60. }
  61. return str;
  62. };
  63. /**
  64. * @private
  65. */
  66. DeveloperError.throwInstantiationError = function() {
  67. throw new DeveloperError('This function defines an interface and should not be called directly.');
  68. };
  69. return DeveloperError;
  70. });