Advertisement
class101

Handling Javascript Exceptions by Adobe John Brinkman

Jul 28th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.      * Produces a human readable stack trace
  3.      *
  4.      * @param   stack
  5.      *          Unformatted Stack string from {exObject}.stack
  6.      * @return  {String}
  7.      *          Formatted stack string
  8.      * @author  John Brinkman
  9.      *          http://blogs.adobe.com/formfeed/2009/03/handling_javascript_exceptions.html
  10.      * @remark  extra infos
  11.      *          Piece of code extracted from pdf and reused in thunderbayes.googlecode.com
  12.      *          to generate a stack trace for auto reporting to the issue tracker
  13.      */
  14.     stackRead: function (stack) {
  15.         "use strict";
  16.         var vLineNumber, vParts, vFunctionName, vDetails, i, j, vLines, vStack = "";
  17.         vLines = stack.split("\n");
  18.         for (i = 0; i < vLines.length; i += 1) {
  19.             if (vLines[i].length > 0) {
  20.                 vParts = vLines[i].split("@");
  21.                 vFunctionName = vParts[0];
  22.                 vDetails = vParts[1].split(":");
  23.                 vLineNumber = vDetails[vDetails.length - 1];
  24.                 if (vLineNumber !== "0") {
  25.                     vStack += "line: " + vLineNumber;
  26.                     if (vFunctionName.length > 0) {
  27.                         vStack += " of " + vFunctionName;
  28.                     }
  29.                     if (vDetails.length > 2) {
  30.                         vStack += " in the " + vDetails[vDetails.length - 2];
  31.                         // Construct a SOM expression of the host object
  32.                         for (j = 2; j < vDetails.length - 2; j += 1) {
  33.                             if (j > 2) {
  34.                                 vStack += ".";
  35.                             }
  36.                             vStack += vDetails[j].replace("[0]", "");
  37.                         }
  38.                     }
  39.                     vStack += "\n";
  40.                 }
  41.             }
  42.         }
  43.         return vStack;
  44.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement