Doubt in try/catch

I am having a string that contains 5 words and separated by space. Now i am just splitting the string through String class split method.

Say , i have following statements

try{

statement1//print something

statement2//here error occurs like ArrayIndexOutOfBoundsException

statement3//print something

}catch()

when there is error in statement2, why the statement1 is ignored. statement1 is not getting printed. I request if anyone explains me

[703 byte] By [ArpanaKa] at [2007-11-27 2:36:20]
# 1
Who said that a try-catch block is a transaction? Statement1 isn't ignored.It is possible that the JVM dies before System.out gets a chance to print anything, though.
CeciNEstPasUnProgrammeura at 2007-7-12 2:55:32 > top of Java-index,Java Essentials,Java Programming...
# 2
Post a small demo code that is generally compilable, runnable and could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html and http://www.yoda.arachsys.com/java/newsgroups.html
hiwaa at 2007-7-12 2:55:32 > top of Java-index,Java Essentials,Java Programming...
# 3

I don't know if this helps, but I've noticed sometimes that if I get an error after printing a line, the printed line can appear somewhere within the stacktrace. It might be something to do with how quickly things are processed, or it may just be a little quirk...

Edit: Reply #1 said it better.

Message was edited by:

SeanJ@

SeanJ@a at 2007-7-12 2:55:32 > top of Java-index,Java Essentials,Java Programming...
# 4

> Who said that a try-catch block is a transaction?

> Statement1 isn't ignored.

>

> It is possible that the JVM dies before System.out

> gets a chance to print anything, though.

Yes you are correct. I tried a sample code and statement was printed. But in my application following is code snippet

String cm = p.getProperty("dir").trim();

if(cm == null) {

dirRadio1.setSelected(true);

}

else {

dirRadio2.setSelected(true);

try {

String arr[] = cm.split(" ");

FoldernameText.setText(arr[0]);

System.out.println(arr[0]);

System.out.println(FoldernameText.getText());

TypeText.setText(arr[1]); //printstacktrace shows error here as Arrayindexoutofboundsexception

SizeText.setText(arr[2]);

FirstlevelText.setText(arr[3]);

SecondlevelText.setText(arr[4]);

}catch(ArrayIndexOutOfBoundsException ex) {ex.printStackTrace();}

in the above code object "p" is of Properties class object. And the property "dir" may have a single word or few set of words as single string. I even dont understand in try/catch block why arr[0] is not set to textfield nor printing atleast. and jvm is not dieing its still up. The property "dir" is currently set to "c:\windows\myproject"

ArpanaKa at 2007-7-12 2:55:33 > top of Java-index,Java Essentials,Java Programming...
# 5

First, catching this AIOOBE is bad style. You can very easily check for the correct array length and shouldn't abuse exceptions for this.

Second, the view probably doesn't update itself because you dont tell it to. But that's a matter to discuss at the Swing section.

Third, did you ever look at what arr[0] might contain? You may be printing an empty String.

CeciNEstPasUnProgrammeura at 2007-7-12 2:55:33 > top of Java-index,Java Essentials,Java Programming...