FAQ Database Discussion Community


Why is eclipse complaining when I try to close BufferedReader in finally block?

java,eclipse,exception,bufferedreader,try-catch-finally
Here is my code: public static String readFile() { BufferedReader br = null; String line; String dump=""; try { br = new BufferedReader(new FileReader("dbDumpTest.txt")); } catch (FileNotFoundException fnfex) { System.out.println(fnfex.getMessage()); System.exit(0); } try { while( (line = br.readLine()) != null) { dump += line + "\r\n"; } } catch (IOException...

Why does the Java Compiler copy finally Blocks

java,jvm,javac,try-catch-finally,try-finally
When trying to compile the following code with a simple try/finally block, it produces the output below (viewed in the ASM Bytecode Viewer): Code: try { System.out.println("Attempting to divide by zero..."); System.out.println(1 / 0); } finally { System.out.println("Finally..."); } Bytecode: TRYCATCHBLOCK L0 L1 L1 L0 LINENUMBER 10 L0 GETSTATIC java/lang/System.out...

What's the equivalent of finally in Swift

swift,try-catch-finally
I try to use the error handling modeling in Swift2. do { try NSFileManager.defaultManager().removeItemAtPath("path") } catch { // ... } finally { // compiler error. } But it seems that there is no finally keyword out there.How can I achieve try-catch-finally pattern in Swift.Any help is welcome....

Trying to close multiple stream with finally

java,file,file-io,try-catch-finally
I have a program that open 3 streams of data but I do not know how to close all of them, here it is the closing part of the program. finally {//cerrando muestras try{ if(muestras!=null){ muestras.close(); } }catch (IOException e) { e.printStackTrace(); }finally {//cerrando salida try{ if(salida!=null){ salida.close(); } }catch...

Adding return in finally hides the exception

java,exception,exception-handling,try-catch,try-catch-finally
I have the following code public static void nocatch() { try { throw new Exception(); } finally { } } Which gives the error Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type CustomException Which is as expected, but adding a return statement in the finally block makes...

Local variable unassigned issue using Try, catch, finally

c#,string,try-catch-finally,listboxitems
I was wondering if i could get a hand please. Can someone explain to me why my string sqrt is unassigned in the finally block? Why do I have to declare it? Why can't it be declared in the try or catch statement? It would make coding less tedious and...