Exceptions and Error Handling
Exceptions
In the event of an error, the WinCC OA JavaScript Manager for Node.js always throws an
exception. If this exception is not handled in the code, the manager terminates with
a Fatal
error. To prevent the manager from terminating, the
exception can (and should) be caught in a try/catch
block.
Exception Handling of the WinCC OA JavaScript Manager for Node.js
// import WinCC OA interface
import { WinccoaManager } from 'winccoa-manager';
const winccoa = new WinccoaManager();
// main function
async function main() {
const dpeName = 'ExampleDP_Arg1.';
try {
const value = await winccoa.dpGet(dpeName);
console.info('Node.js® manager for WinCC OA working');
console.info('Value of ' + dpeName + ' = ' + value);
} catch (exc) {
console.error(exc);
}
winccoa.exit(0);
}
// start the main function
main();
Error Class
The WinCC OA JavaScript Manager for Node.js provides the class
WinccoaError
, which can be used to obtain additional details
about occurred errors. You can find an example of its use and information on which
details are available in the API documentation: WinccoaError