I'm using console.error() function to log errors for my sheets add-on made with apps script. E.g.:
1 var a = null;
2 a.toString();
3 } catch(error) {
4 console.error('Function_1(): ' + error);
5 }
However, my function is pretty big, and when I get some error like "can't use toString() on null
", I'm not sure where the problem is.
I tried using it with throw:
1 var a = null;
2 a.toString();
3 } catch(error) {
4 throw 'Function_1(): '+error;
5 }
But then, I get the line number of throw:
can't use toString() on null at line 4
, while the problem is at line 2
.
I looked at other threads, like: How do you pass back a custom error message from google apps scripts?
But well, it doesn't answer how to provide the correct line number.