How can I avoid throwing EmptyStackException?

The following method will throw an EmptyStackException:
     * Insert HTML into {@link javax.swing.JEditorPane} using {@link javax.swing.text.html.HTMLEditorKit}
     * @throws java.io.IOException Thrown if an I/O error occurs
     * @throws javax.swing.text.BadLocationException Thrown if the location is not a valid location
     * @throws java.lang.Exception Thrown if all other exceptions occur
    private void insertHTML() throws IOException, BadLocationException, Exception {
        // ASSUMES EDITOR IS ALREADY SET TO "text/html" TYPE
        HTMLEditorKit kit = new HTMLEditorKit();
        HttpURLConnection conn = (HttpURLConnection)getURL().openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String data = "";
        StringBuffer sb = new StringBuffer();
        while ((data = in.readLine()) != null) sb.append(data);
        StringReader sr = new StringReader(sb.toString());
        try {
            kit.read(sr, browser.getDocument(), 0);
        } catch (ChangedCharSetException e) {
            // DO NOTHING
        } catch (RuntimeException e2) {
            // DO NOTHING - NOT INSERTING NEW CONTENT INTO BODY ELEMENT
        } catch (Exception e3) {
            e3.printStackTrace();
    }Case in point: If I use "http://www.cnn.com" it will load into JEditorPane (not well, but it loads). If I go to "http://java.net", it will also load that into JEditorPane. However, if I return to "http://www.cnn.com", I get the EmptyStackException on that URL alone; the URL itself only partially loads into JEditoPane as a result.
Is there a workaround for this periodic problem?
Thanx
Phil

I will make a couple of points though.
* It's generally bad practice to delare a method to throw Exception, rather than more specific ones.
* If you do declare your method to throw Exception, declaring IOException adn BadLocationException is redundant, as they're subclasses of Exception
* It's also generally bad to just catch Exception, rather than more specific ones. There are cases where it's legitimate, and without more context I can't tell if this is one of them, but my gut would say no at this point.
* Just printing the stack trace or doing nothing is not generally good exception handling. Again, there are cases where it's legitimate, but in general, it means that the caller of this method thinks everything went fine, and will proceed as if it did, even though it didn't.
* It's genrally considered good practice to use { } around your if/while/etc. bodies even when it's just a single statement and not strictly necessary. It's more consistent, more readable, and prevents logic errors if you go to add more statements to the body later.

Similar Messages

  • Ipod versus itunes - help, how can i avoid throwing my ipod against the wal

    hi there
    i have recently splashed out and bought an ipod video. i was told it is user friendly - but how wrong was that? tried the website but the help is useless to me, then i sent numerous emails to ipod support without response.
    i have squillions of problems with this thing, but my main prob at the moment is that i have more than 12000 songs in itunes and the ipod synchronizes each time i connect but i can't get more than 400 songs onto the ipod and the worst thing is most of those songs are crap.
    i am really angry with this machine, can anyone help me?
    cheers - udo

    When your library is larger than the capacity of your iPod, iTunes by default makes a new playlist called something along the lines of "Owner's iPod" and sets the update option to 'Sync Music - Selected playlists'. It creates a playlist of randomly chosen songs, if you don't like it's choice you can make a playlist of your own to sync from.
    Open iTunes and create a playlist to update your iPod from, call it -iPod to make it the first playlist in Sources. Drag whatever content you want to have into the playlist from your iTunes library. Now connect your iPod and when it appears in the Source list click on the iPod icon to bring up the preference tabs in the main pane. Go to the Music tab and choose Sync Music and the Selected playlists radio button. Choose the playlist you just made from the selection and click Apply. You can also sync from any existing playlists by choosing the same setting, you just need to make sure that the size of the playlists don't exceed the capacity of your iPod:
    iTunes: Creating playlists of your favorite songs
    How to create a Smart Playlist with iTunes
    Another option is to manage your iPod manually. In this mode you can drag songs or playlists from your iTunes library directly to the iPod when it's connected:
    Managing content manually on iPod
    iPod 101: Fill 'er Up
    Something to remember about using an iPod in manual mode is that the "Do Not Disconnect" message will remain on the display until you physically eject the device. In that case use the Safely Remove Hardware icon in the Windows system tray on the desktop and check this link for alternative methods: Safely Disconnect IPod
    One last thing, the advertised song capacity of any of the iPods is a calculation based on 4 minute songs encoded in AAC format at a bit rate of 128 kbps. You need to bear that in mind if you want to get the maximum number on your iPod. Longer songs and songs encoded at a higher bitrate or in uncompressed formats take up more space. If for example you imported full size, uncompressed CD files (AIFF format) you would get significantly fewer on. What format are the songs you have imported? Go to iTunes and right click on one of your songs, choose Get Info>Summary and look at "Kind" to see what format you are using: iTunes: About import settings and hard disk space
    If you have imported uncompressed files they can be converted in iTunes, have a read of these articles:
    How to convert a song to a different format
    How To Choose Import Settings

  • How can i avoid EOFException?

    Dear Friends,
    here raf is RandomAccessFile
    and Record is Object
    my doubt is when i execute is code, it was executed. and also it throws EOFException. i know what is the problem(EOF)
    how can i avoid this exception ?
    please give corrected code..............
    boolean _bolVal = true;
    while(_bolVal)
    try
    objectSize = raf.readInt();
    System.out.println("The Object Size : " + objectSize);
    byte[] byteData = new byte[objectSize];
    raf.read(byteData);
    ByteArrayInputStream bais = new ByteArrayInputStream(byteData);
    ObjectInputStream ois = new ObjectInputStream(bais);
    Record auditObject = (Record)ois.readObject();
    catch(EOFException e)
    _bolVal = false;
    e.printStackTrace();
    Thank You

    Don't read past the end of the file.
    If you don't know how long the file is or which is the last record, you can't avoid EOFException, and there's no reason why you should try. That's what it's there for, to tell you that you're reading past the end of the file.

  • Hi. I purchased a new ipad mini and my brother already has iphone 4,so how can i avoid sharing the same contents that are on his phone? Will creating an other apple id help us in seperating our facetime and icloud accounts as we share our laptop to sync ?

    Hi. I purchased a new ipad mini and my brother already has iphone 4,so how can i avoid sharing the same contents that are on his phone? Will creating an other apple id help us in seperating our facetime and icloud accounts as we share our laptop to sync ?

    Have a read here...
    https://discussions.apple.com/message/18409815?ac_cid=ha
    And See Here...
    How to Use Multiple iDevices with One Computer

  • How can i avoid restarting tomcat server when servlet is modified?

    please advice me that how can i avoid restarting the tomcat server, whenever a servlet file is modified in my application. is their any way ?

    No probs. Here's how I do things...
    1. Install tomcat as normal (e.g. I install to C:\Apps\jakarta-tomcat-5.5.4)
    2. Create a webapps directory in your eclipse project with the following directory structure
    MyEclipseProject
       - src
       - conf
       - webapps
          - MyApplication
             - META-INF
             - WEB-INF
                - classes
                - lib
                - pages3. Set the project's output folder (e.g. bin folder) to webapps/MyApplication/WEB-INF/classes
    4. Put all your jar files in the lib directory
    5. Put JSPs / HTML in the pages directory (you may also want to create additional directories for TLDs, config files etc)
    6. Ensure your web.xml is in the WEB-INF directory
    7. Although it isn't essential I create a context.xml file and store it in META-INF, e.g.
    <Context reloadable="true">
        <!-- Default set of monitored resources -->
         <WatchedResource>WEB-INF/web.xml</WatchedResource>
         <WatchedResource>WEB-INF/conf/struts/struts-config.xml</WatchedResource>
         <WatchedResource>WEB-INF/conf/struts/tiles-defs.xml</WatchedResource>
         <WatchedResource>WEB-INF/conf/struts/validation.xml</WatchedResource>     
    </Context>I use this to set monitored resources that will trigger an automatic appliation reload and to configure JAAS (not shown). See the Tomcat documentation for additional information.
    8. In the 'conf' directory I create a server.xml file used to configure Tomcat (you can copy the one from your <TOMCAT_HOME>/conf/server.xml).
    After copying the file change appBase attribute in the host element to be the full path to the webapps directory. You can also change the HTTP and HTTPS ports if you wish
    9. Download and install the Tomcat Launcher plugin from Sysdeo.
    10. In Eclipse's Preferences menu you will see a new entry for Tomcat. Click this then
    a. Set your Tomcat Version
    b. Set your Tomcat Home
    c. Set "Context declaration mode" to server.xml
    d. Set the configuration file to the full path to your server.xml file created in step 8
    On the "Advanced " sub page select all relevant projects to add to the Tomcat classpath
    On the "JVM Settings" page add all the jars in your WEB-INF lib directory to the class path
    On the "Source Path" page select all relevant projects
    Now if you start Tomcat using the Tomcat icon, you will be able to remote debug your application. If you change web.xml (or any other file in your context.xml watched resources) it will automatically reload. Any changes to JSPs will automatically be picked up (providing your tell your browser not to use the page in cache - e.g. CTRL+F5 in IE)
    There are some limitations that I'm still working on however. Primarily that I haven't included the Tomcat Manager application in my webapps directory, so Sysdeo cannot perform a reload. This means that if I change a source file, and eclipse auotmatically rebuilds, Tomcat doesn't pick up the change unless I either change a watched resource file (e.g. web.xml) or stop and restart Tomcat.
    There's no reason why this can't be fixed, I just haven't got round to it yet.
    I'm sure there are lots of other (probably better) ways of achieving the same thing. This was the first method I tried and it worked, so I stuck with it. I'm not a Tomcat config guru and I'm sure other forum users could provide some improvements should they wish.
    Post if you get into trouble, however I won't be able to respond until next week.
    Cheers,
    Steve

  • I have made a book of my I Photo pictures. In certain layouts there is a textframe. How can I avoid the frame becoming visible in the print if I don't want to write anything? Should I just leave it or should I delete the text "Write your text here" ?

    I have made a book of my iPhoto pictures. In certain layouts there is a text frame. How can I avoid the frame becoming visible in the print if I don't want to write anything?  Should I just leave it untouched or should I delete the instructing text "Write your text here"?

    Most pages have layouts for pictures only or pictures with text boxes. Either select the same layout for that page but the one without the text box or put a space in the text box.
    Putting a space in the text box will avoid getting the warning when ordering that there's an unfilled text box in the book. The box will not be visible in the final product.  You can and should check the book before ordering by previewing it as described in this Apple document: iPhoto '11: Preview a book, card, or calendar before you order or print it
    Happy Holidays

  • How can I avoid (on a mac) getting called on Skype...

    How can I avoid (on a mac) getting called on Skype when I'm not signed in?
    It's really annoying.
    I'm not sure if it's supposed to be that way, but suddenly I get the skype-calling-sound, and I have to log into the skype app to abort the call. The persistent calling bastards kept on calling after I aborted the call and left the app, so I ended up muting my speakers for a while. It really shouldn't have to be this troublesome.

    That's like asking how many cows can I get into a field.  It depends on the size of the field, size of the cows, the terrain of the field, etc.  We could use a bit more information on what you're trying to accommplish:
    1 - where are the photos being downloaded from.
    2 - how big are the photos?
    3 - where are you going to put the photos, i.e. into folders, into an iPhoto library?
    4 - how big is the hard drive in the Mac Pro and how much free space do you have on it?
    etc., etc, etc......

  • How can i avoid displaying runtime error in intractive report

    hi gurus
    my question is, in interactive report when i reach 20th secondary list after that am getting runtime error when i click again. So i wanted to know how can i avoid that run time error.
    regars
    imran

    Hi Imran,
    Basically we can have one basic list and 20 interactive lists.
    Once when we reached to 20th list then it goes to shortdump.
    So, inorder to avoid that we can modify the system field
    SY-LSIND.
    Just see this example and try this. I hope this will be useful for you.
    REPORT  ZSAMPLE1111.
    data: begin of itab occurs 0,
            matnr like mara-matnr,
            mtart like mara-mtart,
            mbrsh like mara-mbrsh,
            end of itab.
    data: begin of jtab occurs 0,
          maktx like makt-maktx,
          spras like makt-spras,
          end of jtab.
    select matnr mtart mbrsh into table itab from mara up to 10 rows.
    loop at itab.
    write:/ itab-matnr, itab-mtart, itab-mbrsh.
    hide itab-matnr.
    endloop.
    at line-selection.
    select maktx spras into table jtab from makt where spras = 'EN' .
    case sy-lsind.
    when '1'.
    loop at jtab.
    write:/ jtab-maktx, jtab-spras.
    endloop.
    when '20'.             * changes see here.
    sy-lsind = 1.
    when others .
    write:/ 'name',sy-lsind.
    endcase.
    I hope this will be helpful for you.
    <REMOVED BY MODERATOR>
    Cheers,
    Swamy kunche
    Edited by: Alvaro Tejada Galindo on Apr 15, 2008 4:01 PM

  • How can I avoid a full scan when ...

    Hello
    How can I avoid a full scan with I apply the aggregate function "MIN"
    SQL> select min(c1) from hh;
       MIN(C1)
             1
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (FULL) OF 'HH'Regards
    James King

    The table 'hh' does not have statistics. Assuming that there is an index on the column c1, statistics are computed on the table and its indexes, you may see a
    INDEX (FULL SCAN (MIN/MAX)) of the index on column 'c1'.

  • When I create an email signature, the text I type is repeated twice in the actual email sent (above and below a line).  How can I avoid this?

    When I create an email signature, the text I type is repeated twice in the actual email sent (above and below a line).  How can I avoid this?

    Try validating your installed fonts and fixing any errors that show up. To do this see this article: http://reviews.cnet.com/8301-13727_7-20085570-263/safari-in-os-x-lion-replacing- text-with-block-a-characters/

  • How can I avoid crash of my iphone 5.

    How can I avoid crash of my iphone 5.

    You swipe left to right on the song, press the red delete button.
    If that does not work, turn off iTunes Match and try again.

  • Travelling to the UK, want to use camera only on my iphone, how can i avoid charges?

    Travelling to the UK, want to use camera only on my iphone, how can i avoid charges, do I just have to turn my phone to airplane more or do more?

    Just put your phone in Airplane mode, then go back into settings & turn WiFi on.
    No nasty surprises...enjoy your trip.

  • Every time I sync my iCal computer with my iPhone 4 or iPad, duplicate entries are generated on both systems. What am I doing wrong or how can I avoid the duplications?

    Every time I sync my iCal on my computer through iTunes with my iPhone 4 or iPad, duplicate entries are generated on both systems. What am I doing wrong or how can I avoid the duplications? I have been doing this for several years and this problem is a more recent issue, like in the last 6 months. I have been deleting the duplicate entries, on both systems, but some duplicates reappear through "general" entries that are connected to the correct color for a Calendar, but not the name. I am going nuts and wasting tons of hours trying to get the 3 calendars to sync without generating duplicate entries.

    Choose one of the Calenders on ONE of the computers OR the MobileMe as the Master / correct account.
    The REINITAILISE the data of MobileMe within preferences on the computer defining the datatransfer correctly (in the advanced box of preferences). The synchronise iphone contacts and calender directly on-line to MobileMe.
    I posted a question on this today, and gave my own reply !
    Regards,
    Kevin

  • How can I avoid duplicates on contacts and how do I get contacts created on iPhone/ipad synchronized on my mac? so far it doesn't work correctly, just sometimes. same for icalendar

    how can I avoid duplicates on contacts and how do I get contacts created on iPhone/ipad synchronized on my mac? so far it doesn't work correctly, just sometimes. same for icalendar

    On your Mac, for duplicates, switching Contacts off then back on in System Preferences > iCloud may prevent duplicates.
    On the iPhone / iPad tap Settings > iCloud. Make sure Contacts and Calendars are swtiched on.
    Try restarting your Mac and your iOS devices when items won't sync as they should.
    To restart an iOS device:  Hold the On/Off Sleep/Wake button down until the red slider appears. Slide your finger across the slider to turn off iPhone. To turn iPhone back on, press and hold the On/Off Sleep/Wake button until the Apple logo appears.

  • How can I avoid automatical quantity confirmation of the items?

    At our case, production is done on sales sales order for some of the materials. When all of the materials at the order are producedi I want to triger the availability check but availability check triggered autpmatically when for the first time the order is created. I don't want the system to make the confirmation automatically. How can I avoid automatical quantity confirmation of the items?
    Thanks in advance for the answers....

    Hi Yasar
    This can be done 2  ways
    1.if you want individual material stocks to be checked for avialbility and deliver them independently then check whether you are using requirement type KSV.
    2. If you want to send the group of materials together and do not want to send a material which is part of group individually ,you can use delivery group with Sales Bill of material  concept . the header material may be a fantom assembly .
    The delivery group is set at the item  category level ,so u can set it for the item categories u want to go together.
    for example  all text package inserts ,extra spares and a material must go together, they  will be part of delivery group.
    I hope this helps
    Regards
    Mandar

Maybe you are looking for

  • How to resize the menu,address and bookmark toolbars. Not the font but the toolbar sizes

    I'm trying to reduce the overall space of the top of the firefox page. I have the menu and the the bookmarks tool bars checked and between those 2 and the address and site header it takes up way to much real estate. My font size is good but the waste

  • Inserting date in iMovie?

    With Apple iPhone videos is there a way to show the date on screen from the meta data in iMovie on an iPad? Thanks

  • Editing info for podcast

    Podcast location: http://www.radio4all.net/responder.php/podcast/podcast.xml?series=The+Sunrise+Oc ean+Bender In iTunes: https://itunes.apple.com/us/podcast/series-podcast-sunrise-ocean/id585890686 My podcast was recently accepted onto iTunes, but th

  • Reinstalling iOS7 apps

    In an effort to clean up my apps I erased the iOS7 Compass and Passbook apps (surprised that this was possible as it hasn't been in previous iOS versions). Howeber, I would like to get them back without having to make a full restore. How do I do this

  • OSA - Transport Appraisal Templates

    Hello, I would like to ask what is the best way of transporting an appraisal template from one client to another. I have checked a few related questions and their responses on this forum and the possible options appear to be a. Usage of RHMOVE30, or