From 1b000bc0639ca1fcd17472c1f11f36c473f5b1e6 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 23 May 2014 06:02:29 -0400 Subject: [PATCH] feature(util) tryCatch{Log} -> exec.try{Log} --- lib/client/key.js | 2 +- lib/server/appcache.js | 2 +- lib/server/console.js | 2 +- lib/server/main.js | 4 +-- lib/server/rest/fs/put.js | 2 +- lib/util.js | 66 +++++++++++++++++++-------------------- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/client/key.js b/lib/client/key.js index 7b97f19e..0644d8fc 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -347,7 +347,7 @@ var CloudCmd, Util, DOM; DOM.scrollByPages(panel, -1); var tryCatch = function(pCurrentFile) { - Util.tryCatch(function() { + Util.exec.try(function() { return pCurrentFile .previousSibling .previousSibling diff --git a/lib/server/appcache.js b/lib/server/appcache.js index 7bca9389..c3219f18 100644 --- a/lib/server/appcache.js +++ b/lib/server/appcache.js @@ -86,7 +86,7 @@ * if watched files would be more then system limit */ var lWatch_f = function() { - Util.tryCatch(function() { + Util.exec.try(function() { fs_watch(pFileName, on_fs_watch(pFileName)); }); }; diff --git a/lib/server/console.js b/lib/server/console.js index cee8062f..b05136f7 100644 --- a/lib/server/console.js +++ b/lib/server/console.js @@ -215,7 +215,7 @@ сommand = args.shift(); - error = Util.tryCatchLog(function() { + error = Util.exec.tryLog(function() { cmd = spawn(сommand, args, options); }); diff --git a/lib/server/main.js b/lib/server/main.js index 8601cf31..6b3e755f 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -135,7 +135,7 @@ */ function mrequire(src) { var module, msg, - error = Util.tryCatch(function() { + error = Util.exec.try(function() { module = require(src); }); @@ -153,7 +153,7 @@ function quietrequire(src) { var module; - Util.tryCatch(function() { + Util.exec.try(function() { module = require(src); }); diff --git a/lib/server/rest/fs/put.js b/lib/server/rest/fs/put.js index 245774f6..682f104f 100644 --- a/lib/server/rest/fs/put.js +++ b/lib/server/rest/fs/put.js @@ -83,7 +83,7 @@ if (error) func(error); else { - error = Util.tryCatchLog(function() { + error = Util.exec.tryLog(function() { diffResult = diff.applyPatch(data, patch); }); diff --git a/lib/util.js b/lib/util.js index d398087f..7013ac95 100644 --- a/lib/util.js +++ b/lib/util.js @@ -204,7 +204,7 @@ this.parseJSON = function(str) { var obj; - Util.tryCatch(function() { + Util.exec.try(function() { obj = JSON.parse(str); }); @@ -217,7 +217,7 @@ this.stringifyJSON = function(obj) { var str; - Util.tryCatchLog(function() { + Util.exec.tryLog(function() { str = JSON.stringify(obj, null, 4); }); @@ -669,37 +669,6 @@ return ret; }; - /** - * function execute param function in - * try...catch block - * - * @param callback - */ - this.tryCatch = function(callback) { - var ret; - try { - ret = callback(); - } catch(error) { - ret = error; - } - - return ret; - }; - - /** - * function execute param function in - * try...catch block and log result - * - * @param pTryFunc - */ - this.tryCatchLog = function(pTryFunc) { - var ret; - - ret = Util.tryCatch(pTryFunc); - - return Util.logError(ret); - }; - this.exec = new ExecProto(); function ExecProto() { @@ -823,6 +792,37 @@ } }; + /** + * function execute param function in + * try...catch block + * + * @param callback + */ + exec.try = function(callback) { + var ret; + try { + ret = callback(); + } catch(error) { + ret = error; + } + + return ret; + }; + + /** + * function execute param function in + * try...catch block and log result + * + * @param tryFunc + */ + exec.tryLog = function(tryFunc) { + var ret; + + ret = this.try(tryFunc); + + return Util.logError(ret); + }; + return exec; }