当前位置: 代码迷 >> PB >> pb9自定义事件(函数)中,有个THROWS,怎么填写
  详细解决方案

pb9自定义事件(函数)中,有个THROWS,怎么填写

热度:89   发布时间:2016-04-29 06:49:52.0
pb9自定义事件(函数)中,有个THROWS,如何填写
pb9自定义事件(函数)中,有个THROWS,里面不知如何填写??

这个THROWS在什么时候起作用??
THROWS出来的异常,是谁去捕获(接管)的??

恳请高手指点!!万分感激

------解决方案--------------------
帮你找了一下帮助


Defining a THROWS clause
If you are using user-defined exceptions, you must define what exceptions might be thrown from a user-defined function or event. You use the Throws box to do this.

When you need to add a THROWS clause
Any developers who call the function or event need to know what exceptions can be thrown from it so that their code can handle the exceptions. If a function contains a THROW statement that is not surrounded by a try-catch block that can deal with that type of exception, then the function must be declared to throw that type of an exception or some ancestor of that exception type.

There are two exception types that inherit from the Throwable object: Exception and RuntimeError. Typically, you add objects that inherit from Exception to the THROWS clause of a function. Exception objects are the parents of all checked exceptions, which are exceptions that must be dealt with when thrown and declared when throwing. You do not need to add Runtime error objects to the THROWS clause, because they can occur at any time. You can catch these errors in a try-catch block, but you are not required to.

Adding a THROWS clause
You can add a THROWS clause to any PowerBuilder function or to any user event that is not defined by an event ID. To do so, drag and drop it from the System Tree, or type the name of the object in the box. If you type the names of multiple user objects in the Throws box, use a comma to separate the object names. When you drag and drop multiple user objects, PowerBuilder automatically adds the comma separators.

The PowerBuilder compiler checks whether a user-defined exception thrown on a function call in a script matches an exception in the THROWS clause for that function. It prompts you if there is no matching exception in the THROWS clause.

You can define a user-defined exception object, and inherit from it to define more specific lower-level exceptions. If you add a high-level exception to the throws clause, you can throw any lower-level exception in the script, but you risk hiding any useful information obtainable from the lower-level exception.