A common usage of catch and finally together is to obtain and use resources in a try block, deal with exceptional circumstances in a catch block, and release the resources in the finally block.
Questions tagged [try-catch-finally]
435 questions
0
votes
3 answers
try/catch block return with finally clause in java
Given the following try/catch block in java:
try{
return;
}
catch(SomeException e){
System.out.println(e);
}
finally{
System.out.println("This is the finally block");
}
and according to this post: "Does finally always execute in Java?" I can…

stratis
- 7,750
- 13
- 53
- 94
0
votes
1 answer
finally{timer.cancel();} not being reached in a transaction
We have the following transaction that sends a heartbeat while it is a running. However in certain situations the heartbeat timer never stops, and the system keeps sending heartbeats even if the transaction is not running. Are we doing something…

Saqib Ali
- 3,953
- 10
- 55
- 100
0
votes
1 answer
TypeError: Cannot call method "closeFileCSV" of undefined -- try/finally block
I currently have a try/finally block of this format:
try {
var someOtherObject = new SomeOtherObject(param1, param2);
someOtherObject.doStuff();
// Object that basically holds a 'result set' of csv rows.
var csv = new CsvObject();
…

Slims
- 864
- 2
- 13
- 31
0
votes
4 answers
in C# is it possible to force control to pass through a finally block if an exception is thrown by an associated catch block?
I know that in Java, if an exception is caught by a catch clause and its catch block throws an exception, control would pass throw the associated finally block (if any) before the thread is terminated. This does not appear to be the case in C#,…

J Smith
- 2,375
- 3
- 18
- 36
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
0
votes
5 answers
Catch an exception with its message using finally block in java
i have following code and i like to get exception message using finally as by using catch i can easily get by its arg.but as much i know i am not able in get exception message using finally.
try {
MyClass obj=new MyClass();
obj.strProName =…

Saurabh Android
- 668
- 8
- 15
0
votes
2 answers
What causes a finally block to execute too soon?
I have a try-catch-finally block that looks like so:
ResultSet rs;
PreparedStatement ps;
Connection conn;
try {
for (int i = 0; i < list.size(); i++) {
** execute SQL query **
}
} catch (Exception e) {
throw e;
} finally {
**…

Mike
- 269
- 3
- 8
- 20
0
votes
2 answers
Object creation inside catch statements
I have a simple program here:
public class Main {
private static Connection connectON = null;
private static PreparedStatement preparedStatementON = null;
public static void main (String args[]) throws Exception {
try{
…

Enrico
- 77
- 2
- 4
- 19
0
votes
7 answers
I won't use try-catch statement in finally blcok. (java)
Here is some java code.
public class SomeClass {
private Connection connection;
public SomeClass(Connection c) {
connection = c;
}
public void someWork(){
Connection c;
try {
// do something
} catch (Exception e) {
…
0
votes
1 answer
How to make finally in try-finally wait for threads to finish?
I'm using JPA in Swing based desktop application. This is what my code looks like:
public Object methodA() {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
boolean hasError = false;
try {
…

jocki
- 1,728
- 16
- 26
0
votes
10 answers
How to explicitly pass a program flow into the finally block in C#?
In Delphi I could do something like this:
try
if not DoSomething then
Exit;
if not DoSomething2 then
Exit;
if not DoSomething3 then
Exit;
finally
DoSomethingElse;
end;
In other means if method DoSomething results false then the…

Wodzu
- 6,932
- 10
- 65
- 105
0
votes
4 answers
try-catch-finally formatexception
I am trying to capture input data from a Textbox by converting it to DateTime format
string yy = string.Format("{0:T}", textBox1.Text);
I wish to use Try-Catch-Finally to produce an Systm.FormatException error and display it in another text…

Rajiv S Mehta
- 50
- 2
- 7
0
votes
1 answer
How can I close the TextWriter stream on Windows XP successfully?
I have a code like the following one for working with a TextWriter stream.
TextWriter TR = new StreamWriter(@"")
try
{
//Logic
}
catch (Exception exception)
{
//Error Reporting
}
finally
{
if (TR != null)
TR.Close();
}
My…

moorara
- 3,897
- 10
- 47
- 60
0
votes
1 answer
Powershell jumps into finally without exception message
I have a problem with my PowerShell code. Sometimes -for whatever reason- my script jumps right into the finally block wihtout any error message from the catch block. This is my PowerShell Code:
try
{
$sleepTime = $reservationDuration -…

andreaspfr
- 2,298
- 5
- 42
- 51
0
votes
1 answer
Where is the syntax error with **finally:* clause?
I'm trying to run Selenium tests for a Django app on production server.
I am getting a syntax error on the finally: clause.
I don't see where the error is and all the tests ran fine in development.
Here is the code:
def activate_revision(self,…

BryanWheelock
- 12,146
- 18
- 64
- 109