0

My function acctualy manages some envolved exceptions. Layer 1 re-throws the exception on layer 2. but it doesn't matter...

my question is simple this works:

throw {
       name:"RangeWithValues",
       message:"The result range cells must be empty",
       //stack:e,
       toString:function(){return ( this.name + ": " + this.message);}
     };

this is not:

throw {
           name:"RangeWithValues",
           message:"The result range cells must be empty",
           //stack:e,
           toString:function(){return ( this.name + ": " + this.message + ( this.hasOwnProperty(stack)?("\nCaused by: "+stack):"") );} 
         };

It prints [object Object] on google preadsheet. I want to print the stack trace. I dont know if i need more information to give you, seems that my question is verry simple =S

White_King
  • 748
  • 7
  • 21

1 Answers1

0

Create a custom error instead of throw the object directly:

function CustomError(name, message) {
    this.name = (name || '');
    this.stack = (new Error()).stack;
    this.message = (message || '') + ' ' + this.stack;
}

CustomError.prototype = Error.prototype;

throw new CustomError('RangeWithValues', 'The result range cells must be empty');

Also see stacktrace.js, a framework-agnostic, micro-library for getting stack traces in all web browsers.

merlin
  • 784
  • 1
  • 15
  • 22