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
1
vote
1 answer

Check for array index to avoid outofbounds exception

I'm still very new to Java, so I have a feeling that I'm doing more than I need to here and would appreciate any advise as to whether there is a more proficient way to go about this. Here is what I'm trying to do: Output the last value in the…
1
vote
4 answers

Catch block doesn't let users continue through the program

I'm having a little difficulty with a catch block in java. Help would be very much appreciated. do { System.out.println ("If you want to exit the program, press 0. To continue, press 1."); try { returnint = Input.nextInt(); …
user2807522
1
vote
2 answers

Is needed Return value or not?, Working with try, catch and Finally: Java

I have this code: private String Style(String Arg, Vector VctrClass) throws Exception { if (Verify that Arg is contained into VctrClass)) { return "Something"; } else { throw new Exception("Error The argument required \""+Arg+"\" doesn't…
joseluisbz
  • 1,491
  • 1
  • 36
  • 58
1
vote
5 answers

Try Catch block in Siebel

I have a script which sends a set of records into a file. I'm using Try - Catch block to handle the exceptions. In the catch block I have a code where it has the pointer to next record. But this is not executing . Basically I wan to skip the bad…
Priya
  • 51
  • 2
  • 4
1
vote
4 answers

What is the functionality of a "finally" block?

class Demo { public static void main(String args[]) { System.out.println("Start main"); try { //exceptional code int x=43/0; } catch(ArithmeticException e) { e.printStackTrace(); …
Vbabey
  • 113
  • 1
  • 2
  • 10
1
vote
0 answers

Cipher AES, no error exception, but init not works

i try to cipher but my outputs after "cipher.init" won't output. Also no exceptions..and I don't know why...(new on android) public void login() { LoginData loginData = this.fragmentBox.getUpdatedLoginData(); String finishString =…
kurtanamo
  • 1,808
  • 22
  • 27
1
vote
2 answers

good practice with try-finally in java?

I ran into a little problem today where I have a piece of code like this, which made me a little uncomfortable... try{ //stuff... } finally { //finally stuff } I wonder if such implementation is a good practice in terms of…
lrl
  • 263
  • 4
  • 18
1
vote
1 answer

Null Pointer Exception after a 'finally' block

I get a NullPointerException at the end of this piece of code : @Override public final void onHandleIntent(Intent intent) { try { Context context = getApplicationContext(); String action = intent.getAction(); …
1
vote
4 answers

How we make Java Code to jump to finally

Here's the piece of code I am seeing 1 session s=null; 2 try{ 3 s= SessionCreator.createSession(); 4 System.out.println("Session Created"); 5 s.validate(); 6 }catch (Exception e){ 7 e.printStackTrace(); 8 }finally{ 9 …
devPassions
  • 23
  • 1
  • 5
1
vote
3 answers

Issue with Try and Catch on Android

As soon i execute the below code, the media is played for 60seconds and my app closes with an error "Unfortunately, YourAPP has stopped." . If i remove "bv.setImageResource(R.drawable.play);" on finally block, the app works perfectly. what is the…
Sai
  • 15,188
  • 20
  • 81
  • 121
1
vote
1 answer

how java implements finally block

I have searched a lot to find the implementation of finally block by java implementers. I want to know how java evaluates finally block. Does anybody know how finally block is defined in java language?
arvin_codeHunk
  • 2,328
  • 8
  • 32
  • 47
1
vote
4 answers

Exception Handling Resumption Behaviour

new to StackOverFlow and fairly new to Java. Been programming in C prior to this and am trying to get the foundations of Java. Just a bit confused about the following code: public class Exercise5 { private static int[] ia = new int[3]; static int x…
SeekingAlpha
  • 7,489
  • 12
  • 35
  • 44
1
vote
5 answers

How to avoid duplicate Cursor.Current statement?

If I am turning on the WaitCursor before a processing task and then turning it back to default, I often get this pattern of code: try { Cursor.Current = Cursors.WaitCursor; MyProcessingTask(); } catch (Exception ex) { Cursor.Current =…
CJ7
  • 22,579
  • 65
  • 193
  • 321
1
vote
2 answers

Is that the best way to release SQLite connection in Java?

I need a good way to close SQLIte connections in Java. After a few suggestion by other users I decided to add to my code a finally block to be sure that closing operation are always executed. public static boolean executeQuery(String query) { …
Luca
  • 1,704
  • 3
  • 29
  • 42
1
vote
4 answers

is it ok to dispose the dataset in finally block and then returning the dataset?

So I am taking over an existing project where the previous coder did many funny things. What I see the most and not really understand is the following block of code finally { if (conn != null) { conn.Close(); ds.Dispose(); …
Johan
  • 8,068
  • 1
  • 33
  • 46