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 PostThe try-catch statement must enclose all statements where an exception could be thrown. Could you list your code, if you're getting errors?
Jump to PostWhy exactly do you need a try catch there?
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. What exception are you trying to prevent though? You may not need the block at all.
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.