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
1 answer
Result Set resource leak even though I am closing the RS?
I am getting 'Resource leak: 'rsHP' is not closed at this location' everywhere I use a rsHP = stmt.executeQuery(query);
Here is a basic layout of what this method does...
public static void method(String x, Connection conn){
Statement stmtHP =…

Cody
- 65
- 3
0
votes
1 answer
Can we catch an exception without catch block?
Suppose I have a try-finally block without catch block, we throw an exception inside the try block. Am I able to catch that exception?
public static void main(String[] args) throws IOException{
try {
throw new IOException("Something went…

SHE
- 121
- 3
- 11
0
votes
1 answer
How to Quit current Powershell IE COM session using Try/Catch/Finally
Looking to terminate IE COM Object browser sessions at the end of my script, in my Finally{} statement.
I would think it be as simple as:
Finally{
$ie.Quit()
}
But its not. the $ie object is unreachable at this stage in the script and no…

Eric Furspan
- 742
- 3
- 15
- 36
0
votes
1 answer
Internal mechanism of the Try Catch Block? How .net framework actually do it?
I know how to use try catch finally blocks. Everybody does.
But I want to know the internal implementation of this great functionality. Does it work like a commit or rollback method in SQL?
Does using try catch lead to performance issue?
Do we need…

Prageeth Liyanage
- 1,612
- 2
- 19
- 41
0
votes
4 answers
try-catch-finally throwing exception in Java problem
I'm Java beginner, but I thought that when using try-catch-finally I don't have to declare the exception using throws SQLException. However if I don't use it the compiler gives me the error:
"unreported exception java.sql.SQLException; must be…

Mike55
- 497
- 13
- 26
0
votes
3 answers
php code logic by version
I want a solution something like: Imagine I have try catch block, it works in any php 5.?.? version but with finally block not in any. my code must be like this:
try {
// some logic
} catch (Exception $ex) {
// some logic
} finally {
…

Arkadi
- 1,153
- 1
- 14
- 35
0
votes
1 answer
Why is there inconsistency in finally block/s execution with uncaught exception
I was recently asked in an interview on the sequence of execution of an exception case in java, where if the exception is not caught and propagated back to calling code, having finally blocks, then are the finally block statements printed ?
If they…

Prajakta
- 89
- 1
- 9
0
votes
2 answers
Will the finally block to be reached if there is "Where (true)" block in try block?
Here's the code puzzled me:
public Integer getInteger(BlockingQueue queue) {
boolean interrupted = false;
try {
while (true) {
try {
return queue.take();
} catch (InterruptedException…

user2916610
- 765
- 1
- 5
- 12
0
votes
3 answers
Valid Commands That Keep A Finally-block From Executing in Java
So I've been assigned to teach a block on exception handling, and I've run into a question I don't have an answer for. What valid (e.g., don't result in either a compiler, or a run-time, error) commands in Java will keep a finally-block from…

Chance
- 988
- 2
- 13
- 29
0
votes
1 answer
Try Catch still not working in Powershell V2 even with “$ErrorActionPreference = “Stop”
I'm running the exact same code on three computers. On computer "A" which is PSV2 (which I'm not allowed to upgrade to PSV3), the following code doesn't do anything EXCEPT print the error Message at the end of execution.
$ErrorActionPreference =…

Michael Hanson
- 1
- 1
0
votes
1 answer
Why is eclipse complaining when I try to close BufferedReader in finally block?
Here is my code:
public static String readFile()
{
BufferedReader br = null;
String line;
String dump="";
try
{
br = new BufferedReader(new FileReader("dbDumpTest.txt"));
}
…

Patrick
- 87
- 1
- 7
0
votes
6 answers
Local variable unassigned issue using Try, catch, finally
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…

Spr89
- 81
- 1
- 9
0
votes
2 answers
Are variables created in the except: stage available in the finally: stage?
I have a try/except*n/finally block of code and I was wondering what the correct way to do the following is:
try:
some_function()
except exceptions.ExceptionA as e:
self.logger.error("Error")
subject = 'error A'
message = 'Check…

Mo.
- 40,243
- 37
- 86
- 131
0
votes
2 answers
the name ds does not exit in the content try catch
try
{
string str = ConfigurationManager.ConnectionStrings["e_con_connection"].ConnectionString;
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("GetProduct",con);
cmd.CommandType =…

Muhammad Azeem
- 15
- 5
0
votes
2 answers
__finally in C++ Builder 2010 losing scope?
Here is a very strange thing which I don't think should happen:
UnicodeString test = "abc";
try
{
try
{
int a = 123;
return a; // This seems to produce a problem with "test" variable scope
}
catch…

Coder12345
- 3,431
- 3
- 33
- 73