Source: Core/RuntimeError.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 an error that can occur at runtime, e.g.,
  9. * out of memory, could not compile shader, etc. If a function may throw this
  10. * exception, the calling code should be prepared to catch it.
  11. * <br /><br />
  12. * On the other hand, a {@link DeveloperError} indicates an exception due
  13. * to a developer error, e.g., invalid argument, that usually indicates a bug in the
  14. * calling code.
  15. *
  16. * @alias RuntimeError
  17. * @constructor
  18. * @extends Error
  19. *
  20. * @param {String} [message] The error message for this exception.
  21. *
  22. * @see DeveloperError
  23. */
  24. function RuntimeError(message) {
  25. /**
  26. * 'RuntimeError' indicating that this exception was thrown due to a runtime error.
  27. * @type {String}
  28. * @readonly
  29. */
  30. this.name = 'RuntimeError';
  31. /**
  32. * The explanation for why this exception was thrown.
  33. * @type {String}
  34. * @readonly
  35. */
  36. this.message = message;
  37. //Browsers such as IE don't have a stack property until you actually throw the error.
  38. var stack;
  39. try {
  40. throw new Error();
  41. } catch (e) {
  42. stack = e.stack;
  43. }
  44. /**
  45. * The stack trace of this exception, if available.
  46. * @type {String}
  47. * @readonly
  48. */
  49. this.stack = stack;
  50. }
  51. if (defined(Object.create)) {
  52. RuntimeError.prototype = Object.create(Error.prototype);
  53. RuntimeError.prototype.constructor = RuntimeError;
  54. }
  55. RuntimeError.prototype.toString = function() {
  56. var str = this.name + ': ' + this.message;
  57. if (defined(this.stack)) {
  58. str += '\n' + this.stack.toString();
  59. }
  60. return str;
  61. };
  62. return RuntimeError;
  63. });