01: /*
02: * CatchCmd.java
03: *
04: * Copyright (c) 1997 Cornell University.
05: * Copyright (c) 1997 Sun Microsystems, Inc.
06: *
07: * See the file "license.terms" for information on usage and
08: * redistribution of this file, and for a DISCLAIMER OF ALL
09: * WARRANTIES.
10: *
11: * RCS: @(#) $Id: CatchCmd.java,v 1.3 2005/10/07 06:50:09 mdejong Exp $
12: *
13: */
14:
15: package tcl.lang;
16:
17: /**
18: * This class implements the built-in "catch" command in Tcl.
19: */
20:
21: class CatchCmd implements Command {
22: /**
23: * This procedure is invoked to process the "catch" Tcl command.
24: * See the user documentation for details on what it does.
25: *
26: * @param interp the current interpreter.
27: * @param argv command arguments.
28: * @exception TclException if wrong number of arguments.
29: */
30:
31: public void cmdProc(Interp interp, TclObject argv[])
32: throws TclException {
33: if (argv.length != 2 && argv.length != 3) {
34: throw new TclNumArgsException(interp, 1, argv,
35: "command ?varName?");
36: }
37:
38: TclObject result;
39: int code = TCL.OK;
40:
41: try {
42: interp.eval(argv[1], 0);
43: } catch (TclException e) {
44: code = e.getCompletionCode();
45: }
46:
47: result = interp.getResult();
48:
49: if (argv.length == 3) {
50: try {
51: interp.setVar(argv[2], result, 0);
52: } catch (TclException e) {
53: throw new TclException(interp,
54: "couldn't save command result in variable");
55: }
56: }
57:
58: interp.resetResult();
59: interp.setResult(code);
60: }
61: }
|