Source: error/AbstractError.js

  1. /*
  2. * Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
  3. * by the Administrator of the National Aeronautics and Space Administration.
  4. * All rights reserved.
  5. *
  6. * The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
  7. * Version 2.0 (the "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License
  9. * at http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. *
  16. * NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
  17. * software:
  18. *
  19. * ES6-Promise – under MIT License
  20. * libtess.js – SGI Free Software License B
  21. * Proj4 – under MIT License
  22. * JSZip – under MIT License
  23. *
  24. * A complete listing of 3rd Party software notices and licenses included in
  25. * WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
  26. * PDF found in code directory.
  27. */
  28. /**
  29. * @exports AbstractError
  30. */
  31. define(function () {
  32. "use strict";
  33. /**
  34. * Constructs an error with a specified name and message.
  35. * @alias AbstractError
  36. * @constructor
  37. * @abstract
  38. * @classdesc Provides an abstract base class for error classes. This class is not meant to be instantiated
  39. * directly but used only by subclasses.
  40. * @param {String} name The error's name.
  41. * @param {String} message The message.
  42. */
  43. var AbstractError = function (name, message) {
  44. this.name = name;
  45. this.message = message;
  46. };
  47. /**
  48. * Returns the message and stack trace associated with this error.
  49. * @returns {String} The message and stack trace associated with this error.
  50. */
  51. AbstractError.prototype.toString = function () {
  52. var str = this.name + ': ' + this.message;
  53. if (this.stack) {
  54. str += '\n' + this.stack.toString();
  55. }
  56. return str;
  57. };
  58. return AbstractError;
  59. });