try{error ("wrong message"); Use error to throw an error //If the error function is in a try statement, the program will not error, but will jump out of the Try statement}catch (e) { ///If the Try statement is followed by a catch statement, you can catch this error message E}
The above is the grammar of Try...catch;
The try statement tries to execute a block of statements and then exits the try statement block instead of interrupting the Aardio program if an error is encountered.
If you use a Catch statement block, you can catch the exception (the catch statement block is optional).
The above is a passage in the Aardio user manual.
Perhaps in the process of using try catch, we often want to return an error directly when an error occurs.
As an example:
= function () {try{ error ("1"); } Catch (e) { return e; }}console.log (Test ()); Console.pause (true);
We return this error message e If an error occurs during test execution.
But it's wrong to write like this. orzing~
A null was returned. (That is, the test function has no return value at all)
Later, after many tests, it was found that using return in a try or catch simply jumped out of the curly brace of a try or catch, so the function was not returned.
To return the catch to the error message E, you can use the following method:
= function () { var err; Try { error ("1"); } Catch (e) { = e; } return err;} Console.log (Test ()); Console.pause (true);
Define a local variable in the function body err, you can assign the error message E to the ERR variable in the catch statement;
Then return in the body of the function, so that you can return the catch to the error message!
Use return in the Try...catch statement in the Aardio function.