Jscript Error Line 8
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this javascript get line number site About Us Learn more about Stack Overflow the company Business Learn more node.js get current line number about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss javascript error line number Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to get javascript try catch error line number JavaScript caller function line number? How to get JavaScript caller source URL? up vote 75 down vote favorite 32 I am using the following for getting the JavaScript caller function name: var callerFunc = arguments.callee.caller.toString(); callerFuncName = (callerFunc.substring(callerFunc.indexOf("function") + 8, callerFunc.indexOf("(")) || "anoynmous") Is there a way to discover the line number from which the method was called? Also, is there a way to
Node Js Console.log Line Number
get the name of the JavaScript file the method was called from? Or the source URL? javascript share|improve this question edited Mar 3 '14 at 21:07 Kara 3,16173147 asked Aug 27 '09 at 12:49 Tal 56331018 2 I don't think this is possible in IE, or else we would have a way to get around there CRAPPY error messages that deliver no detail. But if it is possible I would LOVE to know as well! –Zoidberg Aug 27 '09 at 13:00 add a comment| 13 Answers 13 active oldest votes up vote 20 down vote accepted kangax's solution introduces unnecessary try..catch scope. If you need to access the line number of something in JavaScript (as long as you are using Firefox or Opera), just access (new Error).lineNumber. share|improve this answer answered Aug 28 '09 at 17:16 Eli Grey 22.8k105283 7 Hi, Thanks for that addon. do you know if its possible to get line number from previous call ? Lets say method A calls B , and now in B I would like to know in what line under A the call was made? –Tal Aug 30 '09 at 11:1
need to throw an exception and get the line number and the call stack in JavaScript, specially when we are developing a feature that will be used by other
Javascript __line__
developers. Since JavaScript have far less tools to aid in debugging than other javascript exception line number languages, when we are building a functionality it is handy to throw an exception when the developer that is node error line number using you code need to meet certain requirements. For example: function someFunction(callback){ if(typeof callback != ‘function’){ // throw an exception here }else{ callback(); } } With this code we can achieve it: var http://stackoverflow.com/questions/1340872/how-to-get-javascript-caller-function-line-number-how-to-get-javascript-caller err; try { throw new Error('myError'); } catch (e) { err = e; } if (!!err) console.log(err.stack); if you put this code in the console (chrome) this is the result: Error: myError at :4:11 at Object.InjectedScript._evaluateOn (:777:140) at Object.InjectedScript._evaluateAndWrap (:710:34) at Object.InjectedScript.evaluate (:626:21) This is the code wrapped in a function to enable re-utilization: Compatibility by Mozilla Descktop compatibility: Feature Chrome Firefox (Gecko) Internet Explorer Opera http://www.jomendez.com/2015/02/25/throw-error-line-number-javascript/ Safari Basic support (Yes) (Yes) 10 (Yes) 6 Mobile compatibility: Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Basic support Android 4 (perhaps Android 3, but not Android 2) ? ? ? ? 6 Leave a comment Post navigation « Optimizing code using Object.defineProperty instead of $scope for $watch in AngularJs What’s coming in EcmaScript 6 Part 1 » Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * Name * Email * Website six × five = Comment Yes, add me to your mailing list. Search Recent Posts: CSS Tooltip, without JavaScript or Jquery Prevent angular executing controller twice (Mini-Challenge 11) How to avoid js files cache script bundle with razor State Management in ASP.Net ASP.NET MVC Routers common questions Archives June 2016(2) May 2016(2) February 2016(1) January 2016(1) December 2015(2) November 2015(4) October 2015(6) September 2015(1) July 2015(2) June 2015(4) May 2015(8) March 2015(1) February 2015(10) July 2014(3) CategoriesCategories Select Category AngularJS ASP.NET Best-Practices C# Interview-Questions JavaScript Microsoft Certification Exam mini-challenges Protractor Subscribe to our Newsletter Enter your email address to subscribe to my blog and receive noti
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers https://msdn.microsoft.com/en-us/library/hh699850(v=vs.94).aspx Samples Retired content We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. JavaScript Reference JavaScript Objects Error Object Error Object stack Property (Error) stack Property (Error) stack Property (Error) constructor Property (Error) prototype Property (Error) description Property (Error) message Property (Error) name Property (Error) number Property (Error) stack Property (Error) stackTraceLimit Property (Error) toString Method (Error) valueOf line number Method (Error) TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. stack Property (Error) (JavaScript) Gets or sets the error stack as a string that contains the stack trace frames. Syntax Copy object .stack RemarksThe stack property is set to undefined when the error error line number is constructed, and gets the trace information when the error is raised. If an error is raised multiple times, the stack property is updated each time the error is raised.Stack frames are displayed in the following format: at FunctionName (