Questions tagged [finally]

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

278 questions
-3
votes
2 answers

In try/finally, does it matter what's inside the try?

Is there any functional difference? Connection c = null; try { c = getConnection(); c.doStuff(); } finally { if (c!=null) c.close(); } vs Connection c = null; c = getConnection(); c.doStuff(); try { } finally { if (c!=null)…
pete
  • 1,878
  • 2
  • 23
  • 43
-3
votes
4 answers

Is it good practise to use finally

We use try catch block in our code. What I want to ask here is that using finally block is a good practice. I haven't seen much finally block in code. Is it bad practice?
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
-4
votes
3 answers

Use of finally in java

Consider the code try{ //code } catch(Exception e) { // handle } finally { // close open connections } and this try{ //code } catch(Exception e) { // handle } // close open connections since both are same what is the necessity…
-4
votes
2 answers

What is the reason for the finally block to be lastly executed?

In Java, why does the "finally" block exist: try { ... } catch(...) { ... } finally { // instructions lastly executed when the "try" block is quit } instead of a "firstly" block ? try { ... } firstly { // instructions firstly…
Codoscope
  • 892
  • 1
  • 10
  • 18
-5
votes
1 answer

Need Help C# - Expected catch or finally + cannot be applied to operands

MyProject.MyForms.m_FormBeingCreated.Add(typeof(T), null); try { try { result = Activator.CreateInstance(); return…
user3059135
  • 1
  • 1
  • 1
-5
votes
6 answers

Finally block's content is running before try's content?

How can I fix the below code so that finally part is not overwriten and I can see "This is a regular text" in lbl.Process's Text? try { grd_Order.SaveClicked(sender, e); //This is a button's Clicked event, which redirects to the same page…
HOY
  • 1,067
  • 10
  • 42
  • 85
-6
votes
1 answer

Java exceptions using finally

I am study exceptions in Java and came across this snippet: public class Test { public int b() { try { System.out.println("try block"); return 0; } finally { …
user3126119
  • 323
  • 1
  • 3
  • 10
-8
votes
2 answers

Is there anything in Python like a try-finally except it still raises exceptions normally?

Suppose I want to run some function in Python, ensuring that whether it fails or not some cleanup code is always run. Something like this: try: some_function() finally: cleanup() Ok, simple enough. But hold up! If any exceptions occur in the try…
Aaron Beaudoin
  • 1,107
  • 1
  • 10
  • 23
1 2 3
18
19