Questions tagged [try-catch-finally]

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.

435 questions
-3
votes
1 answer

When using try/catch/finally, with error inputmismatch exception, How do I correctly implement a finally block, WITHOUT getting an error

AND YES I have looked at simialr quesions and NO I cannot find an answer to my question...If you have a question about my question or code. PLEASE ASK. do{ try { System.out.print ("Volume of a cone... V = 1/3(3.14)r^2(h)"); …
user2755775
  • 29
  • 1
  • 7
-3
votes
1 answer

Finally function in php 5.3

Do we have "final block" (try catch final) in php 5.3? I wrote a code in php 5.5 and I have to integrate this code in a system which only supports php 5.3 If we do not have this awesome functionality in php 5.3 then what is equivalent to this? I…
ani
  • 191
  • 1
  • 3
  • 12
-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
-3
votes
1 answer

divisibility program in java - two issues need corrected - explanation below

I have written the program however I have two problems : I do not want the counter i to go from 1 to x because then it would try the divisibility test for every number less than the actual user input. I need it to start i from 2 and go until 12 so…
JavaNewGirl
  • 75
  • 1
  • 7
-3
votes
4 answers

eclipse warning: Finally block doesn't complete normally

I have some code that throws a potential error and I catch these, then jump into a finally block, here it is in 'pseudo' form. private boolean myMethod(ResultSet rs1, ResultSet rs2){ Vector temp = new Vector(); try{ //add info…
DaveM
  • 734
  • 4
  • 11
  • 35
-4
votes
1 answer

try, except and finally in python

def finding(a,b): try: result=a+b return result except TypeError: return "please type only num" finally: return "this line will get print at last" print(finding (5, 2)) I'm getting the output from the…
-4
votes
3 answers

Why is the statement in finally block still executed?

public class ADaemon implements Runnable { @Override public void run() { try { System.out.println("Starting ADaemon"); TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { System.out.println("Exiting via…
-4
votes
7 answers

exception handling and finally block in java

public class Confusion { Confusion(int i) { int j = 5; int[] a = new int[2]; try { a[0] = 4; if (i <= 0) { int k = j / i; } else { System.out.println(j /…
Shantanu Nandan
  • 1,438
  • 8
  • 30
  • 56
-5
votes
5 answers

Try-Catch-Finally c# in Console

I Need to write a Try-Catch-Finally. First of all im new to Programming. Back to the Problem. In the Try-Block i want to open a Text that doesn't exist. in the Catch-Block a Messagebox should show up with the FileNotFoundException. and I still dont…
hrv-ilija
  • 13
  • 2
-5
votes
2 answers

Exception not catched but program exit and finally is executed

I am doing a pressure test on linux server.But I find that my java app always exit without any error message.So I use try-catch-finally and want to get some information about the exit reason.Code like: try{ // the code which make my program exit…
wuchang
  • 3,003
  • 8
  • 42
  • 66
-5
votes
2 answers

How to print the line nuber that caused an exception in Java

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_exception_methods.htm#exception_common_methods This site shows that getLineNumber was included, but I am not able to use it. Thanks ( I am trying to locate a Null Pointer…
-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
3 answers

TryCatch Block in java

try { statement 1 // executing successfully statement 2 // Exception Occured statement 3 // Skip Execution } catch(Exception e) { e.printstacktrace(); } finally { statement 4 } the above code is the basic of trycatch…
RAJESHPODDER007
  • 733
  • 1
  • 8
  • 14
-6
votes
3 answers

What is the finally block for compared to just writing code after the try statement?

In other words, how are these two different? try { // Something that can throw an error } catch { // Handle the error } finally { // Something that runs after the try statement } vs. try { // Something that can throw an…
Phoenix Logan
  • 1,238
  • 3
  • 19
  • 31
1 2 3
28
29