wasCSharpSQLite – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * TclException.java --
3 *
4 * This file defines the TclException class used by Tcl to report
5 * generic script-level errors and exceptions.
6 *
7 * Copyright (c) 1997 Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and
10 * redistribution of this file, and for a DISCLAIMER OF ALL
11 * WARRANTIES.
12 *
13 * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart
14 *
15 * RCS @(#) $Id: TclException.java,v 1.2 2000/04/03 14:09:11 mo Exp $
16 *
17 */
18 using System;
19 namespace tcl.lang
20 {
21  
22 /*
23 * TclException is used to interrupt the Tcl script currently being
24 * interpreted by the Tcl Interpreter. Usually, a TclException is thrown
25 * to indicate a script level error, e.g.:
26 *
27 * - A syntax error occurred in a script.
28 * - A unknown variable is referenced.
29 * - A unknown command is executed.
30 * - A command is passed incorrected.
31 *
32 * A TclException can also be thrown by Tcl control structure commands such
33 * as "return" and "continue" to change the flow of control in
34 * a Tcl script.
35 *
36 * A TclException is accompanied by two pieces of information: the error
37 * message and the completion code. The error message is a string stored in
38 * the interpreter result. After a TclException is thrown and caught, the
39 * error message can be queried by Interp.getResult().
40 *
41 * The completion code indicates why the TclException is generated. It is
42 * stored in the compCode field of this class.
43 */
44  
45 public class TclException : System.Exception
46 {
47  
48 /*
49 * Stores the completion code of a TclException.
50 */
51  
52 private TCL.CompletionCode compCode;
53  
54 /*
55 * An index that indicates where an error occurs inside a Tcl
56 * string. This is used to add the offending command into the stack
57 * trace.
58 *
59 * A negative value means the location of the index is unknown.
60 *
61 * Currently this field is used only by the Jacl interpreter.
62 */
63  
64 protected internal int errIndex;
65  
66 protected internal TclException( Interp interp, string msg, TCL.CompletionCode ccode, int idx )
67 : base( msg )
68 {
69 if ( ccode == TCL.CompletionCode.OK )
70 {
71 throw new TclRuntimeError( "The reserved completion code TCL.CompletionCode.OK (0) cannot be used " + "in TclException" );
72 }
73 compCode = ccode;
74 errIndex = idx;
75  
76 if ( interp != null && (System.Object)msg != null )
77 {
78 interp.setResult( msg );
79 }
80 }
81 public TclException( TCL.CompletionCode ccode )
82 : base()
83 {
84 if ( ccode == TCL.CompletionCode.OK )
85 {
86 throw new TclRuntimeError( "The reserved completion code TCL.CompletionCode.OK (0) cannot be used" );
87 }
88 compCode = ccode;
89 errIndex = -1;
90 }
91 public TclException( Interp interp, string msg )
92 : this( interp, msg, TCL.CompletionCode.ERROR, -1 )
93 {
94 }
95 public TclException( Interp interp, string msg, TCL.CompletionCode ccode )
96 : this( interp, msg, ccode, -1 )
97 {
98 }
99 public TCL.CompletionCode getCompletionCode()
100 {
101 return compCode;
102 }
103 internal void setCompletionCode( TCL.CompletionCode ccode )
104 // New completion code.
105 {
106 if ( ccode == TCL.CompletionCode.OK )
107 {
108 throw new TclRuntimeError( "The reserved completion code TCL.CompletionCode.OK (0) cannot be used" );
109 }
110 compCode = ccode;
111 }
112 } // end TclException
113 }