Questions tagged [finally]

Questions related to the finally block in try-catch construct.

278 questions
0
votes
1 answer

Is it necessary to dispose variables in finally block in static methods?

This example below I found while looking answer to another quiestion. Here that guy disposes response in finally block. Is it really necessary? Is it a GC's work in this case? public static async Task EnsureSuccessStatusCodeAsync(this…
AsValeO
  • 2,859
  • 3
  • 27
  • 64
0
votes
0 answers

finally and return

Possible Duplicate: In Java, does return trump finally? In the below example, class ex8 { public void show() { try { int a=10/0; return; } catch(ArithmeticException e) { …
abson
  • 9,148
  • 17
  • 50
  • 69
0
votes
1 answer

Catch error to end the printwriter

Hi i'm trying to create a program which will allow the user when run to choose whether they want the results i have on a separate file in plain text the console or html on a web browser. The only error that seems to be appearing at the moment is…
Davepop
  • 13
  • 4
0
votes
3 answers

Throwing exception from within catch and also from finally block

I want to throw any exception that occurs while doing MySQL transaction to the application. But before that I want to close any resources that are in open state. But closing these resources might again generate exception which again I would want to…
Vimal
  • 436
  • 1
  • 4
  • 14
0
votes
0 answers

Method goes to "finally" before await ends

I´m testing async/await, and with the following code, it always execute the "finally" section just after the "await" and before it ends its execution. And once inside the "finally", when attempt to execute the "Monitor.Exit(lockerObject);" it throws…
MorgoZ
  • 2,012
  • 5
  • 27
  • 54
0
votes
5 answers

About finally block

I know finally's purpose is to guarantee that some instructions or cleanup code get executed. But what is the actuall difference of using finally or putting the code after the catch block. I mean, give me an example of a case where you need to use…
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
0
votes
0 answers

Why restart() must be in try() in this Java program?

Would you please borrow your wisdom a little bit for me? I am now looking for the reason why restart() method in [add word mode] must be in finally{} section, but I still don't figure out why. For now, both ways can be compiled either I put…
0
votes
1 answer

List becomes empty After query.closeall methodin jdo

public static List getFieldOptionListOfField(PersistenceManager pm, long fieldId) throws NoSuchFieldOptionException { Query query = pm.newQuery(FieldOption.class); try { query.setFilter("this.fieldId == fieldId"); …
user3309305
  • 181
  • 1
  • 7
0
votes
1 answer

Placement of return statement in a method with finally block

I have a simple doubt. In the following two codes, in first return statement is placed inside a finally block public int method1(){ try{ // Some Stuff } catch(Exception e){ e.printStackTrace(); } finally{ return…
Rakesh KR
  • 6,357
  • 5
  • 40
  • 55
0
votes
1 answer

Need to figure out how to use Try, Catch, and Finally in my code?

I am a very beginner programmer, if even that. I have to take a programming course as one of my classes in high school, so I am trying my best to make it through not really understanding much. With that said, please go easy on me. For a project, I…
0
votes
5 answers

scanner closed exception within main method

Can someone please highlight to me the problem With my main method? I am getting the error exception that scanner is closed once I complete first option and try to enter another? I think the problem I am having is from the placement of my try catch…
user2971033
0
votes
2 answers

Best practice using finally? (Not for releasing resources)

To start; just because one can do it doesn't always means one should do it. I'll use a code snippet to explain my question: private StringBuffer sb = new StringBuffer(); //Using StringBuffer because it is thread safe ... /*append to sb in methods…
TungstenX
  • 830
  • 3
  • 19
  • 40
0
votes
1 answer

OCaml: finally clause related issues

type 'a result = Success of 'a | Failed of exn let finally f x cleanup = let result = try Success (f x) with exn -> Failed exn in cleanup (); match result with Success y -> y | Failed exn -> raise exn There are several…
user2821649
  • 57
  • 1
  • 7
0
votes
3 answers

object cannot be resolved in finally block

Why do I get the error: rawData cannot be resoled in the finally block? in: public void parseData(String fileName) throws IOException { try { DataInputStream rawData = new DataInputStream(new FileInputStream(fileName)); …
Clonimus
  • 5
  • 1
  • 8
0
votes
1 answer

Is there a way to override behavior of try catch and finally?

Up till now i have used try catch finally as exception handling mechanism but i want to make a generic finally block that should get perform some necessary action. As in my scenario i have to perform same action after catching any A,B,C kind of…
kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47