Hi,
In our TCF agents, I'm trying to create a common way of reporting exception to client that's common to any commands. For instance, the code snippet shows what I try to do:
public void command(IToken token, String name, byte[] data) {
try {
command(token, name, JSON.parseSequence(data));
} catch (Throwable x) {
if (x instanceof IOException)
fChannel.terminate(x);
else {
try {
// this is the error reporting I desire
fChannel.sendResult(token, JSON.toJSONSequence(new Object[] {
AgentUtils.makeErrorReport(IErrorReport.TCF_ERROR_OTHER, "Exception occured: " + x.getLocalizedMessage()),
}));
} catch (IOException e) {
fChannel.terminate(e);
}
}
}
}
However, in TCF code such as RunControlProxy.java, many done() methods has code like this:
public void done(Exception error, Object[] args) {
String[] arr = null;
if (error == null) {
assert args.length == 2;
error = toError(args[0]);
arr = toStringArray(args[1]);
}
done.doneGetChildren(token, error, arr);
}
where the "assert" requires correct number of arguments returned from agent. That just chokes my attempt above as for different commands I have to return different number of objects even if error has occurred.
I'm wondering if it makes sense to change code in done() in blablaProxy classes to be like this:
public void done(Exception error, Object[] args) {
String[] arr = null;
if (error == null) {
assert args.length >= 1;
error = toError(args[0]);
if (error != null) {
assert args.length == 2;
arr = toStringArray(args[1]);
}
}
done.doneGetChildren(token, error, arr);
}
Thanks.
- Ling