Skip to content
Advertisement

Tag: try-catch

Can I omit try-catch?

I want to fetch an HTML page and read in with BufferedReader. So I use try-with-resources to open it handles IOException this way: Is this a good pattern to catch and instantly throw? And what if I omit try at all and state that function throws IOException? If then any potentional memory leak? Much appreciate any advice! Answer A catch

How can I get Java to read all text in file?

I am trying to get Java to read text from a file so that I can convert the text into a series of ascii values, but currently it only seems to be reading and retrieving the first line of the txt file. I know this because the output is much shorter than the text in the file. The text in

how pattern syntax exception works

how do I use the following statement in try n catch block to chk if the name is valid and display error msg if any? and how to use PatternSyntaxException Answer You don’t need a try…catch to check if the name is valid. The line you wrote: NAME_PATTERN.matcher(name).matches() returns a boolean, true if it matches and false if it doesn’t.

How to apply user defined try catch block in java

I am a beginner and I’ve finished the basic Nim game. Now I want to apply the try catch block to the program to make sure the flow control is perfect. However, the resources I’ve seen for now is to catch the exception in the main method that all the methods created must be called in the try block to

Throw exception vs Logging

Is the following way to code good practice? Moreover, should I.. use only the logger? throw only the exception? do both? I understand that with throw I can catch the exception in another part of the callstack, but maybe additional logging has some hidden benefits and is useful as well. Answer I use both in some cases, logging and throwing

Java catch block, caught exception is not final

I am checking out the new features of Java SE7 and I am currently at this point: http://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html regarding the catch multiple feature, when I came across this statement: Note: If a catch block handles more than one exception type, then the catch parameter is implicitly final. In this example, the catch parameter ex is final and therefore you cannot

Advertisement