on 01-05-2006 6:41 PM
Hi all
I am new to Java !!!
Here is the piece of code that raises the error:
// Method to establish the Link for Outside World
public JCO.Table getLogonClientList() {
try {
myFunction = getFunctionModule();
myConnection.execute(myFunction);
myTable = myFunction.getTableParameterList().getTable("CLIENT_LIST");
return myTable;
}
catch (Exception e4) {
System.out.println(e4.toString());
}
}
When i try to compile the program, i am facing following error:
<b>Error This method must return a result of type JCO.Table</b>
I have already declared myTable(like others such as myConnection, myFunction) as JCO.Table in the beginning of the Class..
Any help please !!!
Thanks
Kay
Hi Kay,
This error is thrown because...
1. For a Successfull Scenario, i.e, if it works without causing any exception then it will return myTable.
2. But what if it causes any exception in the middle.
It will not return myTable. Right.
3. <b>Solution:</b> Add a finally block and return the myTable inside the finally block.
Check this link...
http://www.artima.com/underthehood/finally.html
Hope it helps.
Regards,
Maheswaran.B
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kay,
The use of the finally block is that even if the exception is raised the finally block will get executed.
i.e Immaterial of what ever happens finally, finally block will get executed. If you want some set of statements to be run even if a exception is raised you can include that inside the finally block.
For an example,
You can close the connection in the finally block.
Finally Block is along with try catch syntax where finally block is optional.
For eg.
try{
}
catch(Exception e){
}
finally{
}
So, the functionality will work fine.
Alternative Solution:
Usually in java, the statements which causes exception are included in the try block.
In your case the return statement is not going to cause any exception. Right. So you can remove the return statement from the try block and include it just before the ending brace of your function. This will also work fine.
public JCO.Table getLogonClientList() {
try {
myFunction = getFunctionModule();
myConnection.execute(myFunction);
myTable = myFunction.getTableParameterList().getTable("CLIENT_LIST");
<b>//return myTable;</b>
}
catch (Exception e4) {
System.out.println(e4.toString());
}
<b>return myTable;</b>
}
Hope it helps. Sorry for the delay.
Regards,
Maheswaran.B
Message was edited by: Maheswaran B
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.