Besides throwing exceptions and the "return;" statement

Besides throwing exceptions and the "*return*" statement, what else clauses could complete a code block abruptly?
Originally I thought System.exit() should be one of that kind, and I was totally puzzled by the fact that finally clause dose not work with System.exit(). But after a few thoughts, it becomes clear to me that System.exit() dose not even complete a code block, let alone completing a code block abruptly. So is there other logic that could make a code block complete abruptly?
My question originates from paragraphs in <Thinking in JAVA>, which claim that, I quote,
"Unfortuantely, there's a flaw in Java's exception implementation. Although exceptions are an indication of a crisis in your program and should never be ignored, it's possible for an exception to simply be lost. This happens with a particular configuration using a finally clause"..."This is a rather serious pitfall, since it means that an exception can be completely lost, and in a far more subtle and difficult -to-detect fashion..."..."Perhaps a future version of Java will repair this problem"...
After check with JLS, it seams that it is legitimate to ignore the reason for the abrupt completion of the try block, if the corresponding finally block completes abruptly. I think whether this is a "pitfall, flaw" or not depends on how deeply we language users understand the purpose of the finally clause and it is better for me to know all the possible reasons for a code block to complete abruptly.
So, besides throwing exceptions and the "*return*" statement, what else clauses could complete a code block abruptly?

warnerja wrote:
Case 1: Normal flow (no exception is about to be bubbled to the caller before getting to the finally block) - I'd say we want an exception back due to the failure to close the stream.
Case 2: The finally block was entered through an exception about to be bubbled to the caller - the caller can only get one or the other exception back, either the original exception or the one indicating the failure to close the stream. The finally block has no access to the pending exception however and is unaware of whether there is an exception pending or not. All it knows is an exception occurred during the execution of the finally block, and should throw that or wrap it in another exception - same handling as in Case 1.
try {
  write();
  flush();
finally {
  try {
    close();
  catch (...) {
    log();
}The flush() at the end of try seems kind of redundant, since close() calls flush() anyway. The benefit is that the try statement completion matches the try block ("real work") completion.
If we get to the end of the try block with no exception, then write() and flush() have succeeded and the data is where it needs to be. All that's left is to release the I/O resource, which will always be done in finally.
If there's an exception in the try block, it is propagated out, so we know of any failure that occurred doing the "real work." The I/O resource is still released in finally.
Regardless of how the try block completed, releasing the resource does not affect how the try statement completes, and hence does not supersede how our "real work" completes, which is all we care about. We still log any close() errors for later investigation. What matters to our program is whether all the data was written, and the completion of write() and flush() tells us that.

Similar Messages

  • "Missing Return Statement" although the return statement IS there?

    Hello :) I am currently studying computing science at staffordshire university, java is one of my modules (first year) and im about half way through (still at introduction stage though)... Within my code apparently I have not returned a statement... yet to my believe the return statement is there and in the correct space, i would appreciate it if you could have a look and tell me where I am going wrong please:
    import java.util.*;
    public class ReadWriteArrayApp3
    +{+
    + public static void main(String [ ] args)+
    + {+
    + int[] nums = int double[6];+
    + double result;+
    + readArray(nums);+
    + printArray(nums);+
    + printReverse(nums);+
    + averageArray(nums);+
    result = averageArray(nums);
    + System.out.println("The average of your numbers is " + result);+
    + } // end main+
    public static void readArray(int [] a)
    + {+
    + Scanner kybd = new Scanner(System.in);+
    + System.out.println("Please enter 6 Integers");+
    + for(int i=0; i < a.length; i++)+
    + {+
    + a[i] = kybd.nextInt();+
    + }+
    + }+
    +public static void printArray(int [ ] b)+
    + {+
    + for (int i = 0; i < b.length; i++)+
    + {+
    + System.out.println(b);+
    + }+
    + }+
    + public static void printReverse(int [ ] c)+
    + {+
    + for (int i = c.length-1; i >= 0; i--)+
    + {+
    + System.out.println(c[i]);+
    + }+
    + }+
    + public static double averageArray(int [ ] d)+
    + {+
    + double sum, tot, average;+
    + for (int i = 0; i < d.length; i++)+
    + {+
    + tot = tot + d[i];+
    + average = (tot)/d.length;+
    + if ((average)=(tot/d.length))+
    + {+
    + sum = average;+
    +*  }
    + return sum;+
    + }+
    +} // end application class+
    Console states:
    javac  ReadWriteArrayApp3.java
    ReadWriteArrayApp3.java:49: missing return statement
    * ^*
    *1 error*
    Above in the code I have shown I have made a part bold... this shows the area in which console has a problem with.
    I would really appreciate any help in which I get
    Thankyou
    Victoria
    Edited by: StaffsUniJavaGirl on Nov 12, 2009 9:48 AM

    import java.util.*;
    public class ReadWriteArrayApp3
         public static void main(String [ ] args)
              int[] nums = int double[6];
              double result;
              readArray(nums);
              printArray(nums);     
              printReverse(nums);
              averageArray(nums);
              result = averageArray(nums);
              System.out.println("The average of your numbers is " + result);
         }  //  end main
         public static void readArray(int [] a)
              Scanner kybd = new Scanner(System.in);
              System.out.println("Please enter 6 Integers");
              for(int i=0; i < a.length; i++)
              a[i] = kybd.nextInt();
         public static void printArray(int [ ] b)
              for (int i = 0; i < b.length; i++)
                   System.out.println(b);
         public static void printReverse(int [ ] c)
              for (int i = c.length-1; i >= 0; i--)
                   System.out.println(c[i]);
         public static double averageArray(int [ ] d)
              double sum, tot, average;
              for (int i = 0; i < d.length; i++)
                   tot = tot + d[i];
                   average = (tot)/d.length;
                   if ((averagetot)=(tot/d.length))
                        sum = average;
         return sum;
    } // end application class*line 49 is bold*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • I updated to Firefox 4.0.1 this morning. Norton 5.5 is now disabled and the message states that it is incompatible with 4.0.1. I need the Norton features enabled. Can I go back to 4.0 until this is rersolved?

    I updated to Firefox 4.0.1 this morning. Norton 5.5 is now disabled and the message states that it is incompatible with 4.0.1. I need the Norton features enabled. Can I go back to 4.0 until this is resolved?

    Please do a Live Update to the Norton product.
    They have provided an important update to Firefox 4.0.1.

  • HT3702 I just purchased several items for I-pad and the billing statement says billed to store credit.  What does this mean ?  I have a $20  i-tunes card how do I pay with this ?

    I just purchased several items for I-pad and the billing statement says billed to store credit.  What does this mean ?  I have a $20  i-tunes card how do I pay with this ?  I'm an old **** and don't talk to anyone who plays with I-pad etc.

    That means it should have used your iTunes card credit = store Credit.
    You can check here...
    View Purchase History...
    Sign Into your Account... Click on your account name... Click on Account.... Purchase History
    http://support.apple.com/kb/HT2727
    If you have any problems...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • HT1577 I am attempting to download 2 films from itunes one states download in 54 minute and is 2.01 Gb and the other states 1.64gb and will take 4 hours to download any advice?

    I am attempting to download 2 films from itunes one states download in 54 minute and is 2.01 Gb and the other states 1.64gb and will take 4 hours to download any advice?

    It seems that I have solved my issue by performing a full factory reset (erasing all content, something which I had hoped to avoid) restoring from an iCloud backup did not alleviate the issue, I had to set up as a new iPad.
    Hopefully anyone else else who has this issue in the future will be able to find this.

  • Cannot throw exception from switch-"unreachable statement"

    Hi,
    why is this an unreachable statement?
      public static Msg newMsg(int type, Object data)
          Msg msg;
          switch (type)
              case MsgTypes.MSG_CLUSTER_CREATED:
                  msg=new MsgClusterCreated(); break;
              case MsgTypes.MSG_REPLY:
                  msg=new MsgReply(); break;
              default:
                  throw new MessageTypeNotDeclaredException(); break;     //unreachable statement!!!        
          msg.setDataSegment(data);
          return msg;
      }

    When you throw an exception, the program flow never continues "normally" on the next line --- control is always transferred to the nearest exception handler. Thus control never reaches the break statement on the same line, and "unreachable statements" like this are illegal in Java.
    Solution: remove the unnecessary "break;"

  • WebAuthenticationBroker.AuthenticateAsync throws exception on the desktop

    My code (C# - windows store) uses WebAuthenticationBroker.AuthenticateAsync().
    This method used to work on the desktop until last week, but now it throws exception
    "The process terminated unexpectedly. (Exception from HRESULT: 0x8007042B)"
    The code was not changed and the same code that does not work on the PC, does work on the tablet (Surface).
    The same code can be found in https://github.com/facebook-csharp-sdk/facebook-windows8-sample
    and also at this sample it throws the same exception.
    How can I solve this issue?
    Ronit

    I know it's been a while since the original question was asked, but I've not seen any solutions published for this issue yet. I
    recently faced the same issue. It turned out to be misconfigured permissions on the Internet Explorer's Temporary Internet Files folder. If you have changed that location from default to some custom, please make sure that your account has Full Access permission
    to this folder. I had Administrators group having full access, and my account was a part of administrators group. It worked in normal browsing scenarios, but Windows apps run in a sandbox with stripped permissions, i.e. they don't get permissions granted to
    Admins. Wininet running in the app process was not able to clean up state before starting authentication.

  • 4 Types of exception and the code to handle them

    Dear all,
    I would like to know wheter runtime exception, errors exception, unchecked exception and checked exception are classified as the 4 types of exception.
    What are the java coding of them? please help.

    There are two main families of exception in Java: checked and unchecked.
    The base class for all exceptions is Throwable. Java provides Exception and Error that extend Throwable. RuntimeException (and many others) extend Exception.
    RuntimeException and its descendants, and Error and its descendants, are called unchecked exceptions. Everything else is a checked exception.
    If your method, or any method it calls, can throw a checked exception, then your method must either catch that exception, or declare that your method throws that exception. This way, when I call your method, I know at compile time what can possibly go wrong and I can decide whether to handle it or just bubble it up to my caller. Catching a given exception also catches all that exception's descendants. Declaring that you throw a given exception means that you might throw that exception or any of its descendants.
    Unchecked exceptions (RuntimeException, Error, and their descendants) are not subject to those restrictions. Any method can throw any unchecked exception at any time without declaring it. This is because unchecked exceptions are either the sign of a coding error (RuntimeException), which is totally preventable and should be fixed rather than handled by the code that encounters it, or a problem in the VM, which in general can not be predicted or handled.
    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

  • Pdftk throws exceptions and produces bad output after upgrade

    PDFTK BUG
    I have errors from pdftk, and the pdf files that come out are unusable.
    I just installed the pdftk 1.44-5 (AUR package) in a freshly installed Arch Linux 64-bit system. I installed this package first manually, directly from AUR, and a second time using Yaourt, with exactly the same results.
    [I had used pdftk on the previous install (a couple of months ago) of Arch Linux on the same machine, and that worked without any problems. Also, the latter installed instantly, while the new one had to go through half an hour of an enormous gcc-gcj installation.]
            Nature of the problem
    When I run pdftk I get the following messages:
    tt@pks:~/beazwork$ pdftk body.pdf cat 645   output page.pdf
    Unhandled Java Exception:
    Unhandled Java Exception:
    java.lang.NullPointerException
       at gnu.gcj.runtime.NameFinder.lookup(libgcj.so.12)
       at java.lang.Throwable.getStackTrace(libgcj.so.12)
       at java.lang.Throwable.stackTraceString(libgcj.so.12)
       at java.lang.Throwable.printStackTrace(libgcj.so.12)
       at java.lang.Throwable.printStackTrace(libgcj.so.12)
    When I play back the resulting file, I get the following messages:
    tt@pks:~/beazwork$ xpdf page.pdf
    Warning: Cannot convert string "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1" to type FontStruct
    Warning: Cannot convert string "-*-courier-medium-r-normal--12-*-*-*-*-*-iso8859-1" to type FontStruct
    Warning: Cannot convert string "-*-times-bold-i-normal--20-*-*-*-*-*-iso8859-1" to type FontStruct
    Warning: Cannot convert string "-*-times-medium-r-normal--14-*-*-*-*-*-iso8859-1" to type FontStruct
    Syntax Error: Couldn't read xref table
    Syntax Warning: PDF file is damaged - attempting to reconstruct xref table...
    Syntax Error: Couldn't find trailer dictionary
    Syntax Error: Couldn't read xref table
            Questions
    1. The gcc version currently supplied by Arch Linux is gcc 4.6.3.
    Mine is a 64-bit system; could it be an issue of 32 vs 64 bits?
    2. Is there a simpler, perhaps older, monolithic binary that I can use in the
    interim?
    3. Any way or hope I could be running pdftk again any time soon?
    -------------------------------- 120323 updates
            First answers
    stefan-husmann from aur-dev replied to the above questions as follows:
    1. No
    2. There is pdftk-bin in AUR.
    3. Works fine here
    I replaced pdftk (1.44-5) with pdftk-bin (1.44-4), and got exactly the same behavior. Where do I bang my head?
    problems.
    -------------------------------- 120324 updates
    I decided to seek an alternative to pdftk. While looking for it I found the
    pyPdf module, which provides Python objects for most of the operations
    performed by pdftk.  Note that many web sites mention in this context that
    pdftk has not been maintained for long and has creeping "bit-rot;" apparently,
    its java code no longer matches the gss-gcj compiler, and patches for one or the
    other are not being developed.
    After installing the pyPdf and starting playing with, I discovered that there
    is command-line level Python program, stapler, based on pyPdf, which offer much
    of the functionality of pdftk. Stapler has been improved over the very modest
    original description (for instance, now it doe ranges besides single pages),
    and actually fits my bill well. So this is my solution.
    Unless somebody shows me how to make pdftk viable (THAT WOULD BE LOVELY OF COURSE), with much regret I must
    consider the pdftk closed for the moment.
    Last edited by rugantino (2012-03-25 05:10:32)

    Got the same bug with evince and xpdf.
    Reverting to poppler to poppler-0.18.4-2-x86_64 solved the problem.
    poppler-0.20.0-1-x86_64 (latest update) seems to be broken somehow ?

  • I'm looking to but the iMac 27"  with 2TB Serial ATA Drive   256GB Solid State Drive .  Will time machine automatically back up both the hard drive and the solid-state drive?  Ae there any catches or things to be aware of?

    Will time machine on Lion, Mac OS 10.7, automatically back up both the internal hard drive and the internal solid-state drive both inside a 27" iMac?

    Also, you may find this of interest
    TM 101
    http://support.apple.com/kb/HT1427

  • CSA 5.1, overlapping exceptions and the infamous Rootkit Lockdown Module

    Just looking for opinions and observations from the field:
    By default, the rule placed in the Rootkit Lockdown Module, has the following attributes:
    - Priority Deny
    - Acting as client or server
    - Any TCP & UDP services
    - Communicating with "@(remote)" host addresses
    A similar rule (though not the same, I know this, please don't point this out) in the Personal Firewall rule module, has these attributes:
    - Deny
    - Acting as server
    - Any TCP & UDP services
    - Communicating with any addresses
    There are a couple of other restrictive modules/rules that aren't disabled that when enabled would provide the same protection that the Rootkit Lockdown Module would provide. Any opinions or experiences that anyone would like to share on whether or not you've taken the Rootkit Lockdown Module out of test mode, added exceptions, possibly unattached other rule modules that were doing the same thing, etc.
    As well, does anyone have any further definition on the "@remote" addresses variable? Please be specific if you post a reply.

    I took the rootkit lockdown module out of test mode after making exceptions for the events that were triggering it and it seems to be working OK.
    Since the rootkit is dynamic, I'm going to leave it on unless it causes problems or there are events I can't make exceptions for.
    A have the Personal Firewall module enabled and I made a couple of exceptions for it since it is on all the time.
    I don't want any host acting as a server at any time unless there is a valid reason.
    I deploy all hosts in test mode until tuned.
    We are pretty standardized as far as machine hardware and settings go since we use all one brand and disk images to deploy. That makes for less surprises.
    HTH..
    Tom

  • Disable random generation of  .adf-ctrl-state and the view state

    Hi,
    I'm trying to test a few transaction on an ADF application that would need to be run using a simulator.
    The problem is it is pretty hard to do this using a programmed simulator since everytime the adf-ctrl-state and the viewstate in the browser change, which requires capturing them. To complicate matters further there exists the PPR navigation (at least that's what I think it is) which present a unique _afrLoop id, that also seems to behave differently with different user-agents. 
    My question is, can I do anything with those fiedls that would allow me to have one id to run my transactions ? I understand that some of those ids, like the viewstate act like a session nonce....but are there do I have any options ?
    Thanks,

    You will need to configure your test suite to capture and replay those values. There is also the javax.faces.ViewState variable.
    Here are some good pointers on how to do this in JMeter
    http://one-size-doesnt-fit-all.blogspot.com.au/2010/04/configuring-apache-jmeter-specifically.html
    A more generalized article
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/adfloadstresstesting-354067.pdf

  • How to write a Query a table and the return result is the column name

    Hi All
    Pls advise how to write a query whereas the return result is the
    column name.
    I know there is describe <table_name>;
    Is there any other ways?
    Pls advise
    Tj
    Edited by: user600866 on Oct 14, 2008 12:13 AM

    Data Dictionary table user_tab_columns has all the column names. You can query that and get what ever you want.
    To get the column list of a table just query
    select *
      from user_tab_columns     
    where table_name = <your_table>Edited by: Karthick_Arp on Oct 14, 2008 12:18 AM

  • JAXB 1.0 Throws Exception and WebLogic Server Goes Mad !

    Hi,
    I've currently got JAXB Running within a standalone application running on Tomcat/Apache.
    When I try and Jar it up and run it on Weblogic 7.0 I get the following error being shown.
    The JAXB is being called from the onMessage event in a MessageDrivenBean which is sat on the application server. When it received the first message the server logs go mad repeatedly printing out the info below.
    <10-Jan-03 10:09:48 GMT> <Warning> <EJB> <010065> <MessageDrivenBean threw an Ex
    ception in onMessage(). The exception was:
    java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at uk.tester.deploy.messages.server.messageinbound.MessageHandlerBean.
    onMessage(MessageHandlerBean.java:46)
    at weblogic.ejb20.internal.MDListener.execute(MDListener.java:356)
    at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.
    java:290)
    at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:271)
    at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:2303)
    at weblogic.jms.client.JMSSession.execute(JMSSession.java:2226)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    >
    The actual crash starts when the line
    JAXBContext jc = JAXBContext.newInstance("package structure........messageinbound.helpers.test");
    is called, I've attempted the fix found on this site using the
    public class JAXBClassLoader extends ClassLoader{
    public URL getResource(String name){
    if (name.endsWith("jaxb.properties")){
    name="jaxb.properties";
    return super.getResource(name);
    snippet of code and then changing the context to be
    JAXBContext jc = JAXBContext.newInstance("package structure.........messageinbound.helpers.test",new JAXBClassLoader());
    but this does not seem to help - any ideas please ???????

    Got Passed the first problem by correctly placing jaxb jars on the server and then sorting out the property file location but I still get the following problem.
    javax.xml.bind.JAXBException: Provider com.sun.xml.bind.ContextFactory not found
    I see a number of other postings are talking about this - has anyone got a solution yet ?

  • Fire event works ok in NWDS simulator but throws exception in the PDA MI7.1

    Hi:
    I developed an app, it works OK in NWDS´ simulator but the fireevent explotes when it´s run in the PDA.
    Any idea?.
    Thanks a lot for your time in this post.
    Rocío.

    Hi Christoph!:
    I don´t know why PIOS exception is throw. I comment some lines in my code and what generates this error is the wdfire*event in the main controller.....( event handler was declared but without custom code).
    Thanks a lot for your time.
    Rocío.

Maybe you are looking for