Throwing an exception in C#
p1pah opened this issue · comments
While trying to implement edge-js in our application we have been trying to apply the ability to throw an exception from C# and handling it on the JS side. Following the example from the readme.
`var clrFunc = edge.func(function () {/*
async (dynamic input) => {
throw new Exception("Sample exception");
}
*/});
clrFunc(null, function (error, result) {
if (error) {
console.log('Is Error?', error instanceof Error);
console.log('-----------------');
console.log(util.inspect(error, showHidden=true, depth=99, colorize=false));
return;
}
});`
We see the application blows up on the C# side and the error never gets back to the JS side, our terminal outputs:
undefined:1
(function (f, ctx) { return function (d, cb) { return f(d, cb, ctx); }; })
^
Error: Sample exception
at :1:55
at Object. (C:\Users\bgh\Downloads\VeryTemp12_29_12_32\main.js:85:1)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
Do we have to configure something in order to correctly handle this or is there a bug with the latest release? We are on version 19.3.0
Exceptions should be handled using try{} catch(error) {}
. I have updated https://github.com/agracio/edge-js-quick-start with example.
One final question when talking about errors in this library.... when checking if an error is returned from edge-js e.g.
clrFunc(null, function (error, result) { if (error) { console.log('Is Error?', error instanceof Error); console.log('-----------------'); console.log(util.inspect(error, showHidden=true, depth=99, colorize=false)); return; } });
When would that actually happen? When the library itself returns an error object rather than a result object?