Results 1 to 2 of 2
- 02-23-2009, 09:21 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 24
- Rep Power
- 0
Try- catch block + return + IO package
Hi,
I have a doubt in usage of return stmt in try-catch block. I have a function in which i read a file and that i stored in a String array. All this part will be written in try-catch block. I would like return that string array. Where I have to put this return stmt.
public int[] readDataFromAFile()
{
String tkn[]=null;
try
{
BufferedReader br = new BufferedReader(new FileReader("PrintOutput.txt"));
String line;
while((line=br.readLine())!=null)
{
tkn =line.split(",");
for(int i=0; i<tkn.length;i++)
System.out.println(tkn[i]);
}
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
return tkn;
}
By running this code it is showing 2 errors.
1st error at At catch block.
2nd is at return stmt.
Invalid expression statement.
{
^
error: '{' expected.
return tkn;
^
- 02-23-2009, 10:09 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Similar Threads
-
Question reg try/catch block
By nn12 in forum New To JavaReplies: 1Last Post: 09-16-2008, 05:56 PM -
System.exit() in catch block.
By new_2_java in forum Advanced JavaReplies: 8Last Post: 06-24-2008, 03:45 PM -
Try Catch block issues
By kewlgeye in forum New To JavaReplies: 11Last Post: 04-29-2008, 07:10 AM -
try...catch block
By javaplus in forum New To JavaReplies: 3Last Post: 11-06-2007, 07:53 PM -
Return to try block
By Freddie in forum New To JavaReplies: 2Last Post: 05-11-2007, 08:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks