On Mon, 26 Jul 1999, Suvarna Ayyagari wrote:
> Hi All,
>
> I had a basic questions abt catching exceptions.
>
> I am running an application written in TCl. I am using Tclblend to integrate
> with another java application.
>
> Now for instance I am doing the following
> Now consider the following cases
>
> Case 1
> -------
> set err [catch {set file [java::new java.io.FileInputStream $x]} errMsg]
> if {$err} {java::throw [java::new java.io.FileNotFoundException "file not
> found"]}
>
> Case 2
> --------
> Now lets us say that I don't catch the exception in the code and just
> have the code as follows
>
> set file [java::new java.io.FileInputStream $x]
>
> And let us say $x is not a valid file.
You would generate an error in both cases. A Java exception is Tcl Blend
should act just like a Tcl exception (Tcl calls these errors which are
raised by the error command).
> I get an error message with the "FileNotFoundException" returned to me
> regardless in both the cases.
This depends on the situation. If you want to catch the error and do
something to handle it, then you want to catch the exception and not allow
it to go all the way up the call stack. Most of the time you only need
to call the Java method. If it throws an exception it will be just like
you called the "error" method in Tcl.
> Now I am a bit confused as to when I should need to catch and when I don't
> need to catch the exceptions. If Tclblend is anyway going to catch the
> exception, is there a need for me to put a catch and use
> java::throw to throw the exception.
Perhaps what you are really looking for is info about handling multiple
exceptional conditions in Tcl code. In Java code this can be done with a
try { code } catch (Ex e) { code } finally { code } construct. You can
access this type of exceptional condition handling with the java::try
command. See the docs on how to use it.
later
mo
> I an running into this "do I need to" situation quite a few times and I am
> giving this example
>
> I am using Tclblend 1.2.3, JDK 1.1.6, Tcl 8.0.5 in Solaris.
>
> Any help is appreciated.
> thanks
> Suvarna
>
----------------------------------------------------------------
The TclJava mailing list is sponsored by WebNet Technologies.
To subscribe: send mail to [EMAIL PROTECTED]
with the word SUBSCRIBE as the subject.
To unsubscribe: send mail to [EMAIL PROTECTED]
with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.
A list archive is at: http://www.findmail.com/listsaver/tcldallas/