About the finally block of the try catch.

I know that finally block contains the code that will be executed in any condition of the try catch.
However, I think it is unneccessary, since the stack after the try catch stack will be executed any way.
Any one can help?
for example
try{
System.in.read();
catch(Exception e){}
finally
{ System.out.println("does this matter?");}and
try{
System.in.read();
catch(Exception e){}
System.out.println("does this matter?");

However, I think it is unneccessary, since the stackafter the try catch
stack will be executed any way.That does assume that you catch and handle the error
appropriately.
Of course this is valid as well, and demonstrates
when you would WANT a finally clause.
Connection con = null;
Statement stmt = null;
try{
con  = Database.getConnection();
stmt = con.createStatement("Select * from dual");
// maybe something throws an exception here?
finally{
if (stmt != null){
stmt.close();
if (con != null){
con.close();
The finally block here might throw a null pointer exception itself use
null!=stmt null!=stmt

Similar Messages

  • Trying to install/format an INTERNAL hard drive using Disk Utility gives me "Error: -69760: Unable to write to the last block of the device".   Is that a hardware problem and what could be done about it?

    *** PLEASE NOTE*** - This is a query about an INTERNAL HDD not an external one. Thanks.
    My Mac is a late 2009 model and the current hard drive recently failed. So I bought a new one, exactly the same, albeit 750gb instead of 500gb. The HDD is a Seagate Momentus 7200. Before the my current drive failed I made a time machine back up to an external USB HDD. I've inserted the HDD into the bottom of my Mac, plugged in the USB and started my machine pressing the 'Option' ([ALT]) key. I go into Disk Utility to try and format the new HDD by creating a new partition but I keep getting the messages,
    "Error: -69760: Unable to write to the last block of the device"
    or
    "POSIX: could not allocate memory"
    This is actaully the third HDD I've tried. The first was another Seagate Momentus 7200 500gb, but this time it was a newer model (model number ended in 423AS instead of 420AS - the new one I am trying ends with 420AS, which is the same as the current HDD). I then tried a Western Digital drive but that one didn't even show up in DU. Forums and tech support are suggesting it's faults with the HDDs but surely not three in a row?
    Could this be an issue with another part of my Mac?
    Is there anything else I can do to format the HDD, have I missed a crucial step?

    Did you ever get a resolution to this issue?
    I am having that exact error with a new 512GB SSD from Crucial, in a 15" MBP mid-2010.
    I really wonder now if the stupid SATA cable could be bad - causing the initial SSD fail.  I am replacing it with the EXACT same drive, and getting that "last block" error when i partition in the GUI or from command-line.
    thanks!

  • Why does my mac when i try to format my stick say that unable to write to the last block of the device

    i bought a new mac with osx lion 10.7.why does my mac when i try to format my transcend 8 gb stick in disk utility say that it is unable to write to the last block of the device?please help me

    This may or may not work, but it's worth a try.
    Using Disk Utility, try an re-partition the drive into two partitions, making the second partition very small (a megabyte or two), then see if you can format the first partition normally. Leave the second partition alone.
    If this works, then the first partiton is what you will use.

  • Return in finally block hides exception in catch block

    Hi,
    if the line marked with "!!!" is commented out, the re-thrown exception is not seen by the caller (because of the return in the finally block). If the line is commented in, it works as I would expect. Is this is bug or a feature? I assume the return removes the call to troubleMaker() from the call stack - including the associated exception...
    Christian Treber
    [email protected]
    public class ExceptionDemo extends TestCase
    public void testException()
    String lResult = "[not set]";
    try
    lResult = troubleMaker();
    System.out.println("No exception from troubleMaker()");
    } catch(Exception e)
    System.out.println("Caught an exception from troubleMaker(): " + e);
    System.out.println("Result: " + lResult);
    public String troubleMaker()
    boolean lErrorP = false;
    try
    if(6 > 5)
    throw new RuntimeException("Initial exception");
    return "normal";
    } catch (RuntimeException e)
    System.out.println("Caught runtime exception " + e);
    lErrorP = true;
    throw new RuntimeException("Exception within catch");
    } finally
    System.out.println("Finally! Error: " + lErrorP);
    if(!lErrorP)
    return "finally";

    This is specified in the Java Language Specification, section 14.19.2 .
    -- quote
    If execution of the try block completes abruptly because of a throw of a value V, then there is a choice:
    * If the run-time type of V is assignable to the parameter of any catch clause of the try statement, then the first (leftmost) such catch clause is selected. The value V is assigned to the parameter of the selected catch clause, and the Block of that catch clause is executed. Then there is a choice:
    o If the catch block completes normally, then the finally block is executed. Then there is a choice:
    + If the finally block completes abruptly for any reason, then the try statement completes abruptly for the same reason.
    -- end quote
    "completing abruptly" (in this instance) means a throw or a return, as specified in section 14.1
    Ok? It's not a bug, it's the defined behaviour of the language. And when you think about it, this behaviour gives you the option to do what you want in your finally block.

  • Question about scoping finally blocks

    Hello All,
    I have a piece of code here that has been tricky for me to do a finally block on and it suddenly occured to me that I have maybe been going about exceptions the wrong way. So generally with this type of situation I'll just declare the variable somewhere else above the try and when i do that the scope makes me able to finally block it. Here I can't do that because the declaration actually requires it to have an initial value and it throws it's own exception as a filereader. Sorry about the newb question, but what's the proper way to block out the exceptions and finally block for this code snippet?
    Thanks in advance!
    Josh
    public static void setParameters(File fileName)
              try
                   File fileForProcessing=new File(fileName.getAbsolutePath());
                   //wrap the file in a filereader and buffered reader for maximum processing
                   FileReader theReader=new FileReader(fileForProcessing);
                   BufferedReader bufferedReader=new BufferedReader(theReader);
                   //fill in data into the tempquestion variable to be populated
                   //Set the question and answer texts back to default
                   questionText="";
                   answerText="";
                   //Define the question variable as a Stringbuffer so new data can be appended to it
                   StringBuffer endQuestion=new StringBuffer();
                   String tempQuestion="";
                   //Define new file with the absolutepath and the filename for use in parsing out question/answer data
                   tempQuestion=bufferedReader.readLine();
                   //while there are more lines append the stringbuffer with the new data to complete the question buffer
                   while(tempQuestion!=null)
                        endQuestion.append(tempQuestion);
                        tempQuestion=bufferedReader.readLine();
                   //Set the answer to the stringbuffer after converting to string
                   answerText=endQuestion.toString();
                   //code to take the filename and replace _ with a space and put that in the question text
                   char theSpace=' ';
                   char theUnderline='_';
                   questionText=(fileName.getName()).replace(theUnderline, theSpace);
              catch(FileNotFoundException exception)
                   logger.log(Level.WARNING,"The File was Not Found\n"+exception.getMessage()+"\n"+exception.getStackTrace(),exception);
              catch(IOException exception)
                   logger.log(Level.SEVERE,exception.getMessage()+"\n"+exception.getStackTrace(),exception);
              finally
                   try
                   theReader.close();
                   catch(Exception e)
         }

    Here I can't do that
    because the declaration actually requires it tohave
    an initial value No, it doesn't.Yes it does. But that value can be and should be
    null.I suspect it would be more accurate to say that dereferencing the variable in the finally block requires definite assignment. The declaration itself doesn't require it at all and in fact assignment could be deferred. However, just assigning null in the declaration is still probably the best idea.
    FileReader theReader = null;
    try {
        // yadda yadda
    } finally {
       if (theReader != null) {
           theReader.close();
    }

  • External USB hard drive won't reformat, won't appear in Finder, error: Unable to write to the last block of the device message

    So I just got a new MacBook Air and since I had an external USB hard drive (TOSHIBA MQ01ABD100 1TB) lying around, I decided to use it for back-up. Since I only have just the one hard drive, I decided to partition it into two - one for Time Machine backups, and one for general files (formatted FAT so I could use it with Windows). However, the partitioning failed and I ended up with a partition named disk1s2. Plus, it won't appear on Finder anymore, but it appears in Disk Utility.
    I have tried to reformat it, but I always get the message "Unable to write to the last block of the device".
    Here's the info about my drive:
    Name: TOSHIBA MQ01ABD100 Media
    Type: Disk
    Partition Map Scheme: GUID Partition Table
    Disk Identifier: disk1
    Media Name: TOSHIBA MQ01ABD100 Media
    Media Type: Generic
    Connection Bus: USB
    USB Serial Number: 1220069C
    Device Tree: IODeviceTree:/PCI0@0/XHC@14
    Writable: Yes
    Ejectable: Yes
    Location: External
    Total Capacity: 1 TB
    Disk Number: 1
    Partition Number: 0
    S.M.A.R.T. Status: Not Supported
    And here's for disk1s2:
    Name: disk1s2
    Type: Partition
    Disk Identifier: disk1s2
    Mount Point: Not mounted
    File System: Mac OS Extended
    Connection Bus: USB
    Device Tree: IODeviceTree:/PCI0@0/XHC@14
    Writable: Yes
    Capacity: 999.86 GB
    Owners Enabled: No
    Can Turn Owners Off: Yes
    Can Be Formatted: Yes
    Bootable: Yes
    Supports Journaling: Yes
    Journaled: No
    Disk Number: 1
    Partition Number: 2
    Here's what it says when I run diskutil in Terminal:
    Device Identifier:        disk1
    Device Node:              /dev/disk1
    Part of Whole:            disk1
    Device / Media Name:      TOSHIBA MQ01ABD100 Media
    Volume Name:              Not applicable (no file system)
    Mounted:                  Not applicable (no file system)
    File System:              None
    Content (IOContent):      GUID_partition_scheme
    OS Can Be Installed:      No
    Media Type:               Generic
    Protocol:                 USB
    SMART Status:             Not Supported
    Total Size:               1.0 TB (1000204884480 Bytes) (exactly 1953525165 512-Byte-Units)
    Volume Free Space:        Not applicable (no file system)
    Device Block Size:        512 Bytes
    Read-Only Media:          No
    Read-Only Volume:         Not applicable (no file system)
    Ejectable:                Yes
    Whole:                    Yes
    Internal:                 No
    OS 9 Drivers:             No
    Low Level Format:         Not supported
    I didn't have any data in it prior to the failed partitioning attempt, so there aren't any worries of data recovery. But I'd really like to be able to use this drive again, and save some money (external hard drives are expensive where I live). Anyone with any ideas?

    I'd also like to add that repairing the disk using Disk Utility does nothing but tell me to reformat the drive. So I'm stuck in a loop here.

  • Hi, While installing XQuatrz-2.7.7, the installation blocks at the "destination" level. It asks how to install this soft, "Install for all users" is shadowed, but frozen: i cannot select anything and move on. Any idea how to get that fixed? Thanks!

    Hi,
    While installing XQuatrz-2.7.7, the installation blocks at the "destination" level. It asks how to install this soft, "Install for all users" is shadowed, but frozen: i cannot select anything and move on. Any idea how to get that fixed?
    Thanks!

    It says above 2 relevant and 1 correct answere available .............
    I'm new here so could anyone direct me to these answeres?

  • Printer will not make the final connection to the network

    HP Photosmart c4580 all in one printer
    link systems router
    using the HP add a device wizard, everything proceeds til the final install on the network. a big red X shows up with a message that it can't find the printer on the network this happens with and without the USB connection. all firewalls are turned off.. i have entered the network SSID into the printer configuration settings.
    thanks

    this utility may help:
    http://h10025.www1.hp.com/ewfrf/wc/document?docnam​e=c02114394&cc=us&dlc=en&lc=en&product=3418707&tmp​...
    007OHMSS
    I was a support engineer for HP.
    If the advice resolved the situation, please mark it as a solution. Thank you.

  • I am trying to download the iTunes 10.7 update so that i can update my ipod and just before the final part of the download starts the program stops and says, 'The installer enountered problems before iTunes could be configured'    What a i doing wrong?!

    I am trying to download the iTunes 10.7 so that i can update my ipod. Just before the final part f the download starts the program stops and says, 'The installer encountered problems before iTunes could be configured'
    What am I doing wrong?!

    I am trying to download the iTunes 10.7 so that i can update my ipod. Just before the final part f the download starts the program stops and says, 'The installer encountered problems before iTunes could be configured'
    What am I doing wrong?!

  • Disk Utility Error "Unable to write to the last block of the device"

    I have a WD Caviar Black 1TB drive in an OWC Mercury Elite-AL Pro Quad Interface enclosure.  I have been using it as a Time Machine back up volume without any trouble.  I recently upgraded to Lion and within a week I had a back up fail.  I tried repairing the disk, and then tried erasing it, but that failed as well with the error saying that it was "Unable to write to the last block of the device".  This would seem to be the drive failing, but there are many reports in the Apple forums of back up drives giving this error after a Lion upgrade and I am thinking it's some kind of issue with drive needing some kind of firmware update or special formatting.  I thought you guys might be familiar with the issue and have a fix.  Right now the disk is dead in the water and can't be reformatted.

    I have exactly the same set up I described above in two different locations (one at home, and one at work).  I swap the Time Machine BUP drive when I get to each location and therefore leave my most recent back up at home or work when I leave each place.  That worked fine for a couple of years.  Then after the Lion upgrade, I started having issues with the two drives.  In both cases, I had to lose all my BUP history in Time Machine and start over with a fresh back up.  The set up at home, let me do it by reformatting the drive and then doing a new back up (I was frustrated I lost all the incremental back ups, the whole point to "Time" Machine, but I was able to get a new BUP established and start over).  At work, however, I had the issue described in my original post where I couldn't reofrmat the drive.  I was at a standstill and that's why I posted my issue.  A couple of weeks later, I got to work, plugged in the drive and it let me reformat it like nothing there was never a problem.  I made a fresh Time Machine BUP and everything was back to normal (albeit with a new BUP).  I can't tell you what changed ... It's possible there was a software update that snuck in and updated drivers or something without me being aware of it, but I haven't got a clue.  All I know is it's resolved and I am back to backing up as before ... Most importantly is to note it was not the drive that failed.  So, there's the update for you, I wish you luck with your drive.

  • HT4623 When I was updating my iphone to the new iOS at the final part (when the syncronization is beind done in iTunes), it never finshed. It's been more than 1 hour and it says "syncronizing step 2 of 4". What to do in this case?

    When I was updating my iphone to the new iOS at the final part (when the syncronization is beind done in iTunes), it never finshed. It's been more than 1 hour and it says "syncronizing step 2 of 4". What to do in this case?

    Hi lucaloo,
    Welcome to the Support Communities!
    The article below may be able to help you with this.
    If you can't update or restore your iOS device
    http://support.apple.com/kb/ht1808
    Cheers,
    - Judy

  • HT4743 Why is the Final Episode of The Bachelor, Season 18 not available on iTunes?

    Why is the Final Episode of the Bachelor, Season 18 not available on iTunes yet?

    If you are new to user forums it is expected that you will search though the exiting posts to see if a question is already answered before making a redundant post.  And this has already been answered more times than any one can count.

  • How much is the final prize for the software of logic pro 9 ?

    hello how much is the final prize for the app logic pro ???

    The price you pay does depend on where you live. In Australia, we pay $209.99 (equivalent to US$219.25). But the price will be somewhere close to US$200.

  • Class that contains finally block with out try block

    How can we make a class that will contain finally block with out try block.

    dkpadhy wrote:
    How can we make a class that will contain finally block with out try block.You can�t.
    And frankly it seems to me that you don�t understand what you�re doing.
    Care to explain further?

  • "Object Required" error when using the script block from the code behind

    I try to use the following script block on the code behind page
    <script defer='true' id='NavID' type='text/javascript'>Nav();</script>
    and the function Nav() is on the .aspx page. It gives me the "Object Required" error message. BUT if I add an alert("hello!!!") line inside of the Nav() function, it works fine after the user closes the alert box. Has anyone experienced a similar problem? Please help. Thanks.

    There is no way to troubleshoot this by looking at a picture of the diagram. LabVIEW 6 is almost prehistory and many things have changed, especially the file IO all looks different so it is impossible to tell what you are doing.
    Error 7 is file not found, so most likely your string operations are not correct. What are the full strings? What is the final file name (maybe you are missing a "\" or maybe you are on a different OS type). Put an indicator at the path wire to see what's happening!
    Is this a datalog file?
    (Overall, the code is a bit suspect. Nobody needs a seven frame flat sequence. ) Why do a control and an indicator have the same label?)
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • Satellite U300 connected to TV - Non supported video format

    I am using Toshiba Satellite U300-15q and it has a vga output so i bought a cable and a box that transfers te analogue signal of vga to digital of hdmi so that i can connect it to my 32' TV Sony make. But if i connect it it says on the tv in yellow l

  • How to point Itunes to a new location where music is stored Cannot locate music now it is on an external drive PLEASE HELP!!!!

    Background Info i have recently got rid of my Windows machine an am now using my MacBook as my main machine   On the old windows Desktop   i had my music set up as follows   Itunes libary information: C:\Documents and settings\Lee Robinson\My Documen

  • Problems with sound when upgrading to 3.1.2.

    Hi I have a 2nd Gen iPod Touch and I have just upgraded from 3.0 to 3.1.2. Everything has gone smoothly, but I now have no sounds coming from the iPod. I have reloaded the firmware upgrade and I still have no sound. I have also played with the sound

  • Flash files won't display when using DW CS3

    Anyone else have this problem? The source shows there's a flash file on my html page but it doesn't appear at all. When I made a new page using Dreamweaver MX, I added a flash file, uploaded it, and all was fine (except there was that annoying 'you m

  • Indesign wont print duplex booklet

    im having an issue printing duplex booklet straight out of indesign i have enabled two sided printing on my BROTHER MFC-J6510DW printer dialogue, but when you send it, it doesn't print duplex. for now i have had to add a PPD patch file so i can print