Performance impact on using too much try catch block

I have several questions here:
1. The system that I'm developing requires to be high performance, but I am not sure how will try catch block affect overall performance.
2. I wanted to know which would be more efficient (result in faster processing)
Have several generic try catch OR catch all exceptions individually?
ex:
try {
} catch (Exception e){
}vs.
try{
} catch (MalformedUrlException me){
} catch(SQLException){
}3. Which one would be faster, one big try catch block or several small try catch blocks?
ex.
try{
//read from io file
//query database
//parse data
//write to file
//query database again
} catch(Exception e){
//log exception
}vs.
try{
//read from io file
} catch(FileNotFoundException fnfe){
//log exception
try{
//query database
}catch(SQLException se){
//log exception
try{
//parse data
}catch(SaxParserException saxe){
//log exception
try{
//query database again
}catch(SQLException se2){
//log exception
try{
//write to file
} catch(FileNotFoundException fnfe){
//log exception

1. The system that I'm developing requires to be high performance, but I am not sure how will try catch block affect overall performance.Compared to what? You can't write an equivalent program that doesn't have a try-catch block, so the answer would have to be that it doesn't affect performance at all.
2. I wanted to know which would be more efficient (result in faster processing)Have several generic try catch OR catch all exceptions individually?
You still have it backwards. Do you need to do different things for different exceptions? If so, then that's what you have to do and there is no other code that might be "faster".
Here's what you should do. Write the code that needs to be written. Don't leave out necessary stuff because of performance reasons. (If you left out all your code, the program would run much faster.) Then find out which parts of the program ACTUALLY take the most time and work on speeding them up.

Similar Messages

  • Try Catch Blocks

    This may be too vague of a question but is it bad practice to use one large try catch block? In my mind it seems like it would produce "cleaner" code as far as programmer reading is concerned, but does it affect the program adversely?
    try {
    // code goes here
    } catch (somekindofexception e){
    // print exception e
    } catch (anotherkindofexception e){
    // print exception e
    } // continue for all possible exceptions

    bolivartech wrote:
    I was mistaken it looks like the particular function I was thinking of throws 3 kinds of RuntimeExceptions, but the same idea applies right?
    try {
    } catch (RuntimeException e) {
    System.err.println("Caught RuntimeException: " +  e.getMessage());
    Yes, you can do that if you want to handle all of them the same.
    However, if you want to handle different exceptions differently, you'd catch those specific exceptions, rather than the parent exception type. This is a separate issue from whether you have one big try or lots of little trys.
    NOTE HOWEVER THAT YOU SHOULD NOT CATCH RuntimeException OR ITS DESCENDANTS. RuntimeException indicates an error in your code. Catching it is usually pointless, because you can't recover from it, and trying to continue on will probably lead to corrupt results at best.

  • Macbook using too much memory

    Hi guys,
    Weirdly my macbook pro (mid 2012 model) is using too much ram, core i5, 4 gb ram
    Take a look at this screenshot...
    While I took this screen, I was using only chrome (4 tabs), itunes (wasn't playing anything), and utorrent, nothing else!
    I have a friend who has a Macbook Air 13.3" and with VM, CAD software, music playing, safari, his macbook uses 3.80 gb (same as me without VM)
    I've done a clean install of the OSX 10.9.2 (to remove previous mountain lion files etc), my computer even frozen once, had to manually turn it off...
    Does anyone know what can I do? Thinking about buying buying 2 modules of 4 gb but is there another solution besides buying more ram? This laptop isn't 1 year old =/
    Thank you guys!

    I do not see any problems with the Activity Monitor data in regards to RAM.  As I see it, there are no Swaps and the Wired RAM is normal in my estimation.
    As an aside, i suggest that you try another browser as I alluded to you before.  Also I would get rid of the torrent application.  They are often an invitation to malware or trojans.
    Comparing your friends MBA and your MBP is still not an Apple to Apple situation.  (pun intended)  The Air has ssd storage, your Pro does not which will distort the results.  In addition you would have to compare them with EXACTLY the same criteria.  Doing that is not worth the effort.
    Unless you are having performance issues there is no cause for alarm.
    Do consider increasing it to 8 GB if the bank account allows.  The new OSXs seem happier with that amount.
    Ciao.

  • Thunar-vfs-pixbuf-thumbnailer-1 using too much CPU

    thunar-vfs-pixbuf-thumbnailer-1 process is using too much CPU, noticeably slowing my system...
    here's the screenshot: http://i15.tinypic.com/8fmu8nl.png
    I've tried to kill it, but nothing happens...
    what should I do?

    Hello,
    Try disabling graphics hardware acceleration. Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches.
    You might need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
    Then perform these steps:
    *Click the orange Firefox button at the top left, then select the "Options" button, or, if there is no Firefox button at the top, go to Tools > Options.
    *In the Firefox options window click the ''Advanced'' tab, then select "General".
    *In the settings list, you should find the ''Use hardware acceleration when available'' checkbox. Uncheck this checkbox.
    *Now, restart Firefox and see if the problems persist.
    Additionally, please check for updates for your graphics driver by following the steps mentioned in the following Knowledge base articles:
    * [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]
    * [[Upgrade your graphics drivers to use hardware acceleration and WebGL]]
    Did this fix your problems? Please report back to us!
    Thank you.

  • Why does my Macbook pro said "unplug the device using too much power to re-enable USB devices" when i plug in my iphone's charger to connect my phone with the mac?

    my iphone 5's charger is not working anymore with the mac or the normal plug in neither, i dont know why. whenever i plug in my mac, i have to twist the charger a little and my mac said "USB Devices Disabled: Unplug the device using too much power to re-enable USB devices". of course it cant connect with the itunes in my mac, but somehow it still syncs the music to my iphone... i don't understand why. please help me thanks!

    try resetting the ipad,or change the cable ,it woould work 

  • I updated IOS 6 in my device, it is performing worse. Consuming too much battery in a very short time. How can I "downgrade IOS version?

    I updated IOS 6 in my device, it is performing worse. Consuming too much battery in a very short time. How can I "downgrade IOS version?

    Downgrading isn't supported and wouldn't help.  You need to fix your phone.
    1. Delete and reinstall all email accounts.
    2, Restore the phone in iTunes, first  using a backup and if needed as a new phone.
    iTunes: Restoring iOS software

  • Lightning to usb camera adapter saying attachment uses too much power

    Can anybody help me please as I brought this cable and I get a message saying accessory unavailable or attachment uses too much power . Thanks in advance

    If it's an Apple adapter, take it to an Apple store for replacement.
    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
     Cheers, Tom

  • IPad camera kit error "device uses too much power"

    Got the camera kit....when I attach it I get an error that says the device uses too much power. I've shut down and restarted the iPad several times and still get the same error. Anyone know what I can do?

    I have a camera that uses compact flash cards therefore I have been experimenting with card readers to avoid draining the camera battery when downloading the images to the iPad.
    I have been using the USB part of the camera connection kit with a multi card reader, at first I could not get anything to work, I thought ' the not enough power reason, I sorted out a powered USB hub to try, again no good, I disconnected everything and thought one last try, I put the card in the reader, connected the USB cable to the USB part of the camera connection kit and finally inserted the whole lot into the iPad, to my surprise the light on the card reader came on and a few seconds later 70 nef files were previewed on the screen.
    I repeated the above several times with the same results, I then tried two other card readers again OK, but if I just removed the card and then re inserted it nothing happened, these card readers are no name supermarket specials.
    I may have been lucky but I will continue to try my method and see if it holds up to regular use, so make the physical connection to the iPad the last part of the connection process, I hope this is of some help to others.

  • I cannot watch Flash vids because Firefox uses too much CPU.

    Firefox has become untenable because it uses too much CPU and disrupts Flash videos.
    I've tried disabling or changing the values of plugins. Installing older versions. Nothing helps. It just sucks. It makes me want to pull someone's lungs out.

    Everyone has this problem, since Firefox rigged one of its Plug-ins (something to do with crash reports) about 06 months ago, to max out CPU, thereby sabotaging computer performance (including Flash videos).
    Why or how they haven't fixed it before now strains belief. I have seen the same complaint everywhere. It is a major fuck-up. People want to abandon Firefox in droves, except that none of the other browsers have decent add-ons like pop-up blocker.
    Sort it out, Firefox.

  • Suddenly using too much data?

    Hi everyone,
    I have had my iphone 5 for over a year. For the first couple of months I had problems with using too much data but eventually learned it was my email causing the issues (it was updating automatically). Fast forward this past Christmas. I got an iPad 2, and ONLY use it at home when it's connected to WiFi. To be completely honest, I am not even 100% sure if it supports cellular data at all, although I don't believe it does as there's nothing mentioned of cell data in Settings. Now for the past 2 months, I have been using too much data and having to pay extra on our cell bill and I have no idea what has changed besides updating the iPad and my phone (I just updated my phone a couple days ago) to iOS 7.0.6. The charges aren't enormous or anything, I think it was around $8 extra last month but still, I don't know what has changed. I have already gotten a text from my provider (Telus - Canadian company) today saying that I am now paying for my data usage, because we (my husband and I combined) have used our data alotment for the month. I know the problem is my phone because I used about double the amount of data as he did on our last bill. I tried calling my provider, but I was on hold for ages so I will give it another go tomorrow if I can't get something figured out in the meantime.
    So my questions are: 1) Could it be the iPad using data? I do have it set so that it backs up to iCloud when plugged in (I believe, my sister in law set it up for me), and it syncs my photos from iphone to the ipad. As you can probably tell, I am just slightly technologically illiterate here. I also did get a new keyboard case for it last month that uses bluetooth.
    2) If it's not the ipad, any ideas of where the data could be going? I use my phone mainly for texts and calls, Facebook, email, some internet browsing, but it is set to WiFi. I mostly use it at home where there is a WiFi connection. Although my young kids do play Angry Birds and watch some videos when we are driving. I don't believe the amount of games they play and videos they watch have changed though, that has been an ongoing thing.
    Thanks for any advice, I would like to nip this in the bud before something gets out of control.

    Update: I got my bill today, and as suspected I have used way more than half of our shared data plan (which is 1GB - I used 1760Mb). I have had my cellular data either completely turned off, OR turned on but not allow any apps to use it (I noticed that I was having some issues with not being able to send/receive texts if my data was compeltely turned off... Not sure why, but that's another post I guess)  since I started this post. I called Telus and she wasn't able to tell me where any of my data was going, she just kept saying "well you've only spend $3.69 in data for last month" and asked me if I was completely closing out apps, which I do every other day or so. She just recommended that I download an app called My Data Manager to set a limit on how much cellular data I am using, however the app doesn't tell me WHERE the data is going which is my concern. So I'm kind of back at square one. I'm not sure if I should allow my kids to play their games and do as I normally do on the phone until the data gets racked up and then I can try to figure out where it's going, or what. My billing cycle started on March 18 and since then I have used 1MB (approx.) of data, but I was in the US for 4 of those days and had the data turned off completely, so again not sure where that 1MB went. One thing I have started doing that is new, is playing downloaded music (music that I have on iTunes, and put onto my phone) in the car. I thought since it is music that I have put onto the phone (not streaming music) it wouldn't be using any data, but on March 19 (the day before we left for the US), I was playing music in the car with my data turned off, and when a song ended and I tried to play another one it said that the cellular data was turned off and I needed to turn it on. I didn't turn it on, but I did put the phone into airplane mode and was able to play my music that way. Could that be using cellular data? If so, then I know where it has been going!

  • Get "using too much power" message when charging with USB

    I have a 4th gens iPod Touch that appears to have a number of issues:
    1. get "using too much power" message when charging with USB
    2. can't re-boot
    3. unable to access iCloud Backup, Ignore and Settings button inactive
    4. unable to unlock unit when using the Home button to turn the unit on

    Try:                                               
    - iOS: Not responding or does not turn on           
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable                                                       
    - Try on another computer                                                       
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar                                     

  • HT4106 unplug the device using too much power to re-enable USB devices

    iPad min cannot be changred, it shows
    unplug the device using too much power to re-enable USB devices

    Try unplugging it. Give your iPad a reset by holding down the sleep and home keys for about 20 seconds (until it reboots) then try again.

  • Firefox uses too much cache when commenting in Facebook - 45MB when the text is only 1kB - why?

    Firefox uses too much cache when commenting in Facebook. I wrote a comment up to 1000 characters and my PC crawled. I had to wait several times for the text to catch up with my typing. I cleared caches after entering my comment and it freed up 45MB of RAM from the firefox.exe process in Windows Task Manager. Why does Firefox use 45MB when the text is only 1kB?
    Another time the firefox.exe process began at 88MB and went up to 250MB whilst writing a comment, reducing to 170MB afterwards. Firefox hogs the CPU too (I tried the CPU hogging tips but none was the solution to this), but the memory usage is the issue because the CPU would not be hogged if less data was being moved or cached.
    I accept some slowness on an old 1.2GHz 512MB PC but the facebook issue is much worse than other sites.

    Dheart wrote:
    signor_rossi wrote:
    schivmeister wrote:this is a flash issue
    Of course it is, but there isn't much we can do about it, isn't it? Therefore I suggested firefox3, to alleviate things a little (it does it for me). Flash doesn't even work at all for me in Opera, I only get a grey window where the video should be.
    Bye, signor_rossi.
    The newest version of flash Plugin only works with Opera 9.5 beta. If you want to use flash with the stable Opera find an older version of the flash plug in.
    Thanks for the hint, will keep that in mind in the case I will switch to Opera again (used it for a while because Firefox2 scrolling was bad, with 3 it is much better). Besides, there is a new flash version in the repos.
    Bye, signor_rossi.

  • HT4101 It says accessory will use too much power.......what do I do?

    I have bought the lightning to USB camera adapter for my new iPad but it is saying the accessory uses too much power? What do I do? Please help

    Is the adapter an Apple product or 3rd party?
    Try this first - Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
     Cheers, Tom

  • To upload photos from my pc onto my ipad using a usb stick. I bought a camera connector kit and tried placing the usb stick onto one of the white square adaptors, stuck it into the ipad2 and I got 'the device uses too much power'' message. Pls help.

    I am not very familiar with the ipad2. I wished to transfer some photos from my pc (not an apple pc but that is the only one I have) to my ipad2 as I thought it would be easier to cull them, edit, crop etc to create albums for our recent trip (the photos are already on the pc and no longer on the camera memory card). When I place the usb stick on the adaptor and stick it onto the Ipad2 I keep getting 'device uses too much power/ requires too much power' message. I read somewhere on the internet that a usb hub could be used to solve the issue but that did not work either. What am I doing wrong? Is there actually a way around this problem. If not why does apple sell this product for Ipad users at all?
    Thank you for any help/ solution you can offer.
    Regards

    I'd ask that on the iPad forum.
    https://discussions.apple.com/community/ipad

Maybe you are looking for

  • Hi: I think this is a common question - I seem to have two Apple ID's and need to know which one to use when activating a replacement iphone5

    Hi: I have 2 Apple ID's. The first is the ID I established when I bought my first MacBook Pro several years ago. When Mobile Me ended, I migrated to a new Apple ID that is associated with icloud and that ID has its own password. On the first iphone 5

  • What is the point of the Mail Activity pane (vs. Window Activity)?

    I was happy to see this new little pane in the lower left corner, but I have yet to actually see it display anything. The old, separate Activity Window still shows everything in great detail, but I'd prefer the more compact version... if that's what

  • Connecting a used ipod touch

    Hello, I've just bought a used iPod Touch (4th generation) off ebay, and can't get it to connect to my windows computer. When I turn it on the iPod shows a screen with a cable pointing to the iTunes logo. When I plug it in to the computer nothing hap

  • How to tune segmapsize in solaris

    Hi Does anyone has better explanation on how to tune segmapsize in Solaris 8. How to check configured value. From below command what can be concluded ? root@mdsmdcs1 / # kstat -n segmap module: unix instance: 0 name: segmap class: vm crtime 182.90681

  • Raw recruit needs help with basic thumbnail

    I have searched the help files and the discussion groups and cannot find a reference to the creation of a thumbnail. Therefore, I am confident everyone in the world but me knows how to do that. But I need a thumbnail! How do I make or get or find or