Allowed in all component types.
The throws declaration is used to declare that any code within a module that sets $procerror to a negative value will raise an exception, and can bubble this exception up to its caller.
operation doSomething throws ; Operation doSomething can raise exceptions ; Code that could set $procerror to a negative value. <your code here> end
If the code sets $procerror to a negative value, an exception is thrown and $procerror and $procerrorcontext hold the exception information. These functions now have exception scope, meaning they can be inspected inside a catch block.
If the module itself does not catch the exception, it will bubble up to the calling module where it will be handled if the caller has an associated catch block. If there is no catch block, the exception will continue to bubble up the call stack until it is either handled by a catch block or reaches application level and exits as an uncaught exception.
Note: The calling module does not need a throws declaration to be able to raise an exception to the next level in the call stack.
A throws declaration is equivalent to wrapping a module inside a try block without a catch or finally statement.
Tip: It can be good practice to use the throws declaration in a module even if it contains try…catch…endtry constructs. It provides early feedback on programming mistakes so that you can correct them, and helps to identify and catch errors that may not be expected.