Permalink
Browse files

Slightly improved our `SAFE` function

  • Loading branch information...
1 parent 41fcc3a commit e33e44f44df39a55a7fd49289d5b7dc20ecfce1f @diegocr diegocr committed Jul 19, 2014
Showing with 3 additions and 4 deletions.
  1. +3 −4 jspdf.js
View
@@ -407,18 +407,17 @@ var jsPDF = (function(global) {
}
events.publish('addFonts', { fonts : fonts, dictionary : fontmap });
},
- SAFE = function(fn) {
- fn.foo = function() {
+ SAFE = function __safeCall(fn) {
+ fn.foo = function __safeCallWrapper() {
try {
return fn.apply(this, arguments);
} catch (e) {
var stack = e.stack || '';
if(~stack.indexOf(' at ')) stack = stack.split(" at ")[1];
var m = "Error in function " + stack.split("\n")[0].split('<')[0] + ": " + e.message;
if(global.console) {
- console.log(m, e);
+ global.console.error(m, e);
if(global.alert) alert(m);
- console.trace();
} else {
throw new Error(m);
}

0 comments on commit e33e44f

Please sign in to comment.