Exception Handling
Error handling in OneVision Scripts is essential for building robust and reliable computer vision applications. It ensures that your program can handle unexpected issues and continue operating or provide feedback. Error handling is particularly important in computer vision applications where operations such as image processing, data analysis, and hardware interaction can encounter various issues.
Try-catch blocks
OneVision Scripts use try-catch blocks to handle exceptions, similar to many other programming languages. The try block contains the code that may throw an exception, and the catch block handles the exception. The programm first tries to run the try block, and if an error occurs, it runs the catch block.
try {
// Code that may throw an exception
} catch {
// Code to handle the exception
}
For example:
function divide(a: number, b: number): number {
try {
let result = divide(10, 0);
return result;
} catch {
console.log("An error occurred: " + error.message);
return 0;
}
}