this code works:
the question is:
how can I use the read object outside the try-catch block ?
it gets out of scope so the compiler prints an error.
I don't want to put everything in the try-catch block as it becomes inefficient and ugly. I don't want to push the exception higher up though. Am I missing something here ? Any suggestions ?
code:<HR>Code:try{<P> FileInputStream in = new FileInputStream("object.txt"); ObjectInputStream sIn = new ObjectInputStream(in);<P> Record read = (Record)sIn.readObject(); System.out.println(read);<P> }catch(FileNotFoundException ex1){System.out.println("File not found");} catch(IOException ex2){System.out.println("IOException");} catch(ClassNotFoundException ex3){System.out.println("ClassNorFound");}
the question is:
how can I use the read object outside the try-catch block ?
it gets out of scope so the compiler prints an error.
I don't want to put everything in the try-catch block as it becomes inefficient and ugly. I don't want to push the exception higher up though. Am I missing something here ? Any suggestions ?