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:
Namhyeon Go 2026-01-21 17:51:26 +09:00
parent 3fbcd71bc5
commit 8d27e1fd02

5
app.js
View File

@ -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;