Questions tagged [finally]

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

278 questions
0
votes
2 answers

Do this will call finally?

suppose that i have this code. if exception is InvalidData, do this will call finally to clean resources. while(CanWork){ try { .... } catch (InvalidDataException e) { …
Daniel
  • 197
  • 2
  • 16
0
votes
1 answer

Variable scope try, finally

This is my code. I have a try and finally statement. Within the try block i have a fixed statement which sets a pointer variable. try { fixed (char* chRef = p) { //code } } finally { chRef = null; } Im struggling for a way…
user2390368
  • 101
  • 2
  • 9
0
votes
3 answers

Can I miss the catch clause to throw exception to its caller?

What kind of problem may occur for this code? I think even exception occurs, this code can throw the exception to its caller. So it does NOT generate any trouble. How can I improve it? public static void cat(File named) { RandomAccessFile input =…
Zachery
  • 131
  • 2
  • 8
0
votes
2 answers

Terminate workers

I've got a function which starts a number of worker threads. Each worker thread is encapsulated by an object, and the destructor of that object will try to join the thread, i.e calls if (thrd_.joinable()) thrd_.join();. But it is unknown a priori…
MvG
  • 57,380
  • 22
  • 148
  • 276
0
votes
1 answer

try catch finally

Maby this is simple for you, but for me is not. I have this code: Private int InsertData() { int rezultat = 0; try { if (sqlconn.State != ConnectionState.Open) { sqlconn.Open(); } …
gligom
  • 17
  • 5
0
votes
1 answer

parameter index out of range mysql at the end of finally block

Most of my code seems to work, but I keep on getting Exception in thread "main" java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). It happens after the finally block in readDatabase(). It doesn't get to the…
rasen58
  • 4,672
  • 8
  • 39
  • 74
0
votes
4 answers

Finally block on Using - Does it fire as in other contexts of Finally?

In some code I routinely work with (and have written a few times), code like the following has been used: using (StreamWriter sw = new FileWriter(".\SomeFile.txt")) { // Perform file IO here... } finally { sw.Close(); } I'm familiar with…
Andrew Gray
  • 3,756
  • 3
  • 39
  • 75
0
votes
1 answer

Java catch/finally blocks skipped completely?

We have a ThreadPoolExecutor-back task execution module. Some tasks are apparently finished in the application codes but the worker code somehow skip all the try/catch/finally and just go pick up the next task, causing the previous one to miss…
teddy
  • 2,158
  • 4
  • 26
  • 34
0
votes
6 answers

Finally block to behave differently

I have a condition like this String str = null; try{ ... str = "condition2"; }catch (ApplicationException ae) { str = "condition3"; }catch (IllegalStateException ise) { str = "condition3"; }catch (Exception e) { str =…
Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190
0
votes
1 answer

SQL SMO exception causes finally block to be skipped?

I created a VS2010 Windows service project. In it I invoke the method Microsoft.SqlServer.Management.Smo.Database.ExecuteWithResults(expression). In my scenario the expression contains invalid SQL, so the call fails with an exception as expected. …
Dan
  • 1,215
  • 1
  • 10
  • 22
-1
votes
2 answers

finally: txt.close() SyntaxError in Python

I can not use finally:txt.close() to close a txt file. Please help me out. Thank you! txt = open('temp5.txt','r') for i in range(5): try: 10/i-50 print(i) except: print('error:', i) finally: …
rawkiwi
  • 13
  • 1
-1
votes
3 answers

Finally block excecution

When the below method is called it's printing output as 6 but I am expecting output as 5 as I have re-assigned n = 5 in the finally block. Can anybody please help me with this? public static int p() { int n = 0; try { n = 6 ; …
-1
votes
1 answer

Is it legitimate to have business logic inside a finally block?

I have a method entangled with control structures. It has many ways to exit. Before leaving the method I need to do some final processing. Instead of repeating the same logic before each exit or refactoring that logic in a method and calling it…
Carlos Nunes
  • 1,929
  • 2
  • 16
  • 20
-1
votes
1 answer

What was the reasoning behind not special-casing a resolved value of undefined from Promise#finally?

Background The TC39 proposal-promise-finally, which is now part of the ES2018 specification, lists the following key points also paraphrased on MDN to describe exactly what the method does. promise.finally(func) is similar to promise.then(func,…
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
-1
votes
2 answers

Why value from inside of "try" is printed during catching the exception?

I have code like this: class ExceptionTest{ public Integer divide(int a, int b) { try { return a/b; }finally { System.out.println("Finally"); } } } public class Three…
Gregory
  • 65
  • 6