mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-01-27 11:39:18 +00:00
Add fallback to UseObject error handling
The UseObject function now accepts an optional fallback callback, which is invoked if the main callback throws an error. This improves error handling and allows custom recovery logic.
This commit is contained in:
parent
3fbcd71bc5
commit
8d27e1fd02
5
app.js
5
app.js
|
|
@ -188,7 +188,7 @@ if (typeof CreateObject === "undefined") {
|
|||
}
|
||||
|
||||
if (typeof UseObject === "undefined") {
|
||||
var UseObject = function(progId, callback, dispose) {
|
||||
var UseObject = function(progId, callback, dispose, fallback) {
|
||||
if (typeof callback !== "function") {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -204,6 +204,9 @@ if (typeof UseObject === "undefined") {
|
|||
var obj = CreateObject(progId);
|
||||
try {
|
||||
return callback(obj);
|
||||
} catch (e) {
|
||||
return (typeof fallback === "function" ?
|
||||
fallback(obj, e) : null);
|
||||
} finally {
|
||||
dispose(obj);
|
||||
obj = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user