Hi, I need to do a file read and extract all the numbers in the text file to be used in my java program. However, I'm having some problem with the try and catch statement. Must the try and catch statement be in the main loop only? Can't I used it in a normal class?
Sunshineserene 0 Junior Poster
Recommended Answers
Jump to PostA try block, like any other block, has to occur within some sort of method. You can't put it out in the field declarations. Sorry.
It looks like you're trying to protect the assignment to that 2D array - have you been getting an exception there?
Jump to PostYes. That means you'll have to do the assignment in a method. You can declare the array:
private double[][] residuescores;
will not throw any exceptions, and if you put it where you have it now, it'll be a class-level field, which means it'll be visible to all …
Jump to PostOkay - you mean you want to do something like this:
try { my2DArray = readMyTextFile(); } catch (ReadTextFileException rtfe) { // NOT a real exception! recoverFomError(); }
Something like that, but with real code?
So you can see why you can't do that where you …
Jump to PostErm, I don't know where to try and catch (read my text file) so that I can equate the output of the reading to my 2D array.
It seems like you're treating the "try" and "catch" as if they're the importan bits of the operation. They're not. A "try" block …
All 15 Replies

coil
Sunshineserene 0 Junior Poster

coil
jon.kiparsky 326 Posting Virtuoso
Sunshineserene 0 Junior Poster

coil
jon.kiparsky 326 Posting Virtuoso
Sunshineserene 0 Junior Poster
jon.kiparsky 326 Posting Virtuoso
Sunshineserene 0 Junior Poster
jon.kiparsky 326 Posting Virtuoso

coil
Sunshineserene 0 Junior Poster
jon.kiparsky 326 Posting Virtuoso
Sunshineserene 0 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.