Why  catch any other exception other than Exception ?

Hi,
I am under the following impression. Is my understanding correct?
why do I need to catch any other exception other than Exception in the catch block.
If I write code :
try{
//checked code
}catch(Exception e){
e.printStackTrace();
e.getMessage();
}the e.printStackTrace(); and e.getMessage(); will belt out the exact error message and the cause of it.
Why then should I use any narrower excetpion than Exception (Like SQLException, in case of SQL code). ?

You don't have to catch the specific exceptions. However, it makes the code clearer. If you have catch exception, then the next person to maintain that code, has to then study the try block to determine what, if anything, might be thrown in that block, in order to be able to effectively modify the code, whereas when you have catch CNF, then the next person to maintain the code knows, automatically, that that is the only possible exception (checked anyway) that should be thrown in that block.
The other reason, is so that when varying (and especially unrelated, i.e. SQL and Parse) exceptions can be thrown, they can be handled differently.
So, as a summary, it is either a matter of form, or a matter of completeness. But, yes, you can simply catch Exception, if you wish.
Edit: The first point is also valid even when you are the only one who will ever see the code. I can't count the number of times where I have written something then had to revisit it years later, and thought to myself, WTF. (I have a tendency, if I don't "watch" myself to not comment my code enough, and, at the same time, tend to get a little more "clever" or "cryptic" than I absolutely have to.)

Similar Messages

  • Ok on my iPad 3 I pad to change my password everyday, so I reset it now it's fine but bigger problem I can't connect to wifi at home with out it asking for proxy ip server and a bunch of things .  Very frustrating can't connect to any other than my tmobli

    OK people who is able to help me fall back in love with my ipad3? Here go, I was in love then I lost it when I had to change my password every time I got back on. So it told me to reset it . I did. It worked yay.!!
    so now I was trying to get online sitting outside my house an I was asked to put in password and ip address along with other weird things I had never had to do befor. So even inside it tells me to do this , so someone please help me please thank you.
    Want A Personal Answer?
    1,199,824 people are answering.

    Does the iPod connect to other networks?
    Did the iPod connect before?
    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    - Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • I cannot click on "next page" or any other than the first page on Music Wishlist

    Music>My Wishlist
    I cannot click on "Page 2" or "Page ..." or "Next"
    Is this a problem with the current version?
    Anyone else having this problem?
    Thanks,
    digisound

    Both the Yahoo! Toolbar extension and the Babylon extension have been reported to cause an issue like that. Disable or uninstall those add-ons.
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Catch all uncaught exceptions in GUI

    Is there a way to catch any uncaught exceptions within my GUI so that I can do some special handling instead of it being echoed to the console?

    It's actually an AWT class that's catching the errors: EventDispatchThread. There is a way to override that mechanism, but it's unsupported, and the only place it's documented is in the source code of that class. Here's an example.
    public class MyApp
      public static void main(String[] args)
        System.setProperty("sun.awt.exception.handler",
                           "MyApp$EDTErrorHandler");
        // create and show the GUI
       * This class will be instantiated by the
       * EventDispatchThread the first time it
       * encounters an exception or error.
      public static class EDTErrorHandler
         * This method is invoked by the AWT event
         * dispatch mechanism when an unexpected
         * exception or error is thrown during
         * event dispatching.
        public void handle(Throwable t)
          // handle the error
    }

  • JSP file extension: other than .jsp

    Is it possible with Tomcat to have a JSP file with an extension any other than .jsp? If it is what should I do to make it possible?
    Please point me to the right direction.
    Cheers,
    Alexei

    In the default web.xml the.jsp extension is mapped to the jsp servlet. You can override this or add your own mapping:
      <!-- The mapping for the JSP servlet -->
      <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
      </servlet-mapping>Change the url-pattern to what you want and add to the web app's web.xml.

  • At 10.18 yesterday, other than a recurring email from Holland and Barrett (now blocked) I have received no messages although I see there are 20 messages waiting

    Since recurring promotional email arrived yesterday my mailbox seems to have become locked to any other than the recurring mail (which I have now blocked) but am still unable to receive any emails at all.

    I would go to your webmail and sign in there. then I would read and delete any email that I don't want to see if one of those is blocking the other mail from transferring.

  • Runtime exception for other than programming error.

    In a conversation the question arose whether it could be a case of throwing a runtime exception for anything other than a bug. The tutorial on oracle site says "These Usually Indicate programming bugs" leading to think that can be used in situations in which there is no bug.
    Anyone have a practical example of a runtime exception when there is no bug?
    Thanks.

    937643 wrote:
    Ok. But. Do you think that in these cases the use of a runtime exception could be considered a bad practice?That's actually a matter of some debate.
    On the one hand, Java has defined two major kinds of exceptions since the very beginning (unchecked exceptions, which are RuntimeException, Error, and their descendants; and checked exceptions which are everything else). The intended use of those was that checked exceptions should be for things that can normally go wrong in the execution of a program, even without a bug or without a major internal JVM error, such as a failed attempt to persist something or a network connection dropping--stuff that a programmer might normally be expected to deal with; while unchecked exceptions were created for things that a programmer would not normally handle in his code (except possibly at major architectural boundaries), like buggy code or an internal JVM failure.
    With the rule about having to catch or declare checked exceptions, but not unchecked ones, that makes it easy for programmers so say, "Okay, I know exactly what can go wrong here that I might be expected to handle and I can therefore choose what to do with it; there will be no surprises. But I don't have to deal with problems that are outside my normal responsibility, like somebody passing me a null when they shouldn't have." It gives a programmer a nice bit of control, and the ability to know he hasn't missed something, kind of like the type safety provided by a strongly typed language.
    At least that's the theory.
    In practice, most checked exceptions either just get bubbled up to the next layer (via a throws clause), or caught wrapped in a fairly generic layer-appropriate exception and rethrown. There's not a whole lot of use made of what checked exceptions provide, and there's a lot of ugly boilerplate code that doesn't do anything useful for the app but is just there to satisfy the compiler.
    So, some people think that checked exceptions are useless, or mostly useless, and favor unchecked exceptions in most or all cases. I believe that's part of the philosophy of Spring, but I'm not totally sure.
    The idea is that since most of the time you can't do anything about exceptions that might be thrown to you, it's wasteful and pointless to have all that code to catch and rethrow. In this viewpoint, it would be better if, for example, not providing a throws clause at all meant that you could throw any exception. Any given code can still catch specific exceptions that it knows it can handle, but we don't have to write a bunch of code notating something that we're not really doing anything about.
    Personally, I used to be totally in the checked exception camp. However, all the pointless boilerplate is wearing me down. I'm still not completely convinced though, and here's why: If I'm calling a method, I'd like to at least be able to see what might go wrong, so that I can decide how to deal with it. If all exceptions were unchecked, and the throws clause were optional, a conscientious developer could still provide it, and list the unchecked exceptions his method might throw to me, and/or he could document them in the javadoc comments. But a lot of developers won't do that, or even if they start to, as their method evolves, without the compiler to enforce it, they won't keep it up to date.
    So there are advantages to both approaches. I personally would to know that the information will always be available to me, but for the small percentage of the time where I actually use it (like handle one specific exception one way and some other exception differently), I'm not sure if it's worth the overhead.

  • Can't log in to any other user account except admin

    I have one computer (out of a lab full of 36 computers) that has a problem creating additional accounts beyond the first.
    I can set up multiple other accounts (either admin, standard, or managed accounts), but I can't log in to any other accounts except the admin account. Here's what I do:
    1. When the computer was unpacked I set up the admin user, and automatic login of the admin user using the usual Apple first run setup windows.
    2. In System Preferences -> Accounts, I click the lock and enter my admin password so I can make other accounts. This works fine.
    3. I create an account and give it a password (I've tried blank passwords too).
    3a. The system warns me that automatic login is turned on (set to the admin user currently). I click the "Keep Automatic Login" button. The other account is now created and all looks well; I can see it's home folder in the Users folder.
    4. I switch to the Login Options view, and choose that other account from the automatic login popup menu.
    4a. The system prompts me for the account password. This is where the problem happens.
    4b. On 35 of the computers, this works fine. One 1 computer, the system warns me that "You did not enter the correct password for your user account." I can click OK there, but nothing I enter for the password works.
    I also tried logging out from the admin user, and I simply can not log in to any other account. I've tried one letter passwords; I've tried blank passwords; I've tried variations on account names; I've tried all-caps; I've tried all-lowercase. I can log in to the admin account with no problems; I can set up as many other accounts as I like, but I can't use any of them.
    Any ideas? Should I just wipe the hard drive and re-install? That's certainly a viable option, but it's baffling me why it's only this one out of 36 computers having the problem.

    Smells like a corrupted OS installation. Two options. Erase & Install or hook it up to a good machine, via target disk mode, and clone the booted machine, using something like Carbon Copy Cloner, SuperDuper!, etc., after erasing and reformatting the calcitrant machine, and see if that fixes things.

  • I bought an external hard drive for backups to use with Time Machine, but however when I try to connect it with the other windows laptop it doesn't work ? intact it doesn't work on any other device except my MAC ?

    I bought an external hard drive for backups to use with Time Machine, but however when I try to connect it with the other windows laptop it doesn't work ? intact it doesn't work on any other device except my MAC ?

    Do not worry about it.
    Time Machine needs that your external drive is formatted in HFS+, or better known as "Mac OS Extended (Journaled)". This filesystem is used by Apple on Macs and Windows cannot read or write drives formatted with this filesystem, being this the reason why all your devices do not read the external drive except your Mac.
    You can only use your external drive to make Time Machine drives. If you store anything different, you may damage the Time Machine structure, so it is better not to use it as a drive to store other data. Instead, get another external drive to do it or create a second partition on the external drive formatted in FAT32 by using Disk Utility > http://pondini.org/OSX/DU3.html FAT32 can be read by Windows PCs

  • File Data Source:  does not support any other host except LOCALHOST?

    I am using US 1.0.3.
    This exercpt is from the OTN iLearn Subscribed course titled "Oracle9i UltraSearch New Features" on operating system file access:
    "The file protocol is used only for the machine that launches the crawler. You can not specify any other host for this kind of URL, except LOCALHOST."
    Does it mean that US 1.0.3 can not be used to search other file servers on the network? For example, we have US 1.0.3 installed on a server S1 which is on a network with other servers (e.g. S2). I want to use US to search files in the folder myDir on server S2. So I tried to create a file data source with this URL:
    file://\\s2\myDir\
    But I got this error:
    Invalid file protocol URL: file//\\s2\myDir\
    Hostname of the file URL "file://\\s2\myDir\ is not "localhost".
    My question:
    (1) Can US 1.0.3 search files on a different server than the one US is running on?
    (2) If so, how to specify the URL using the above example for it to work?
    (3) If not, how about the newer version of US, 9.2 or 9.02? Can they be used to search files on other network servers/drives?
    (4) If no to question (3), is there any plan to support this in the future version of US?
    My comment: Not able to search other servers really limits the userfulness of US. I really hope Oracle will consider adding this capability.
    Thanks!

    More on my previous questions:
    Since I posted my previous question, I have read on the 1.0.3 online help that we can define remote crawlers to crawl "on a remote machine other than the Oracle Ultra Search database". So I assume this is how to make US to search on other servers. In the online documentation it also includes the following paragraph on "Remote Crawler Profiles Page":
    "Use this page to view and edit remote crawler profiles. A remote crawler profile consists of all parameters needed to run the Ultra Search crawler on a remote machine other than the Oracle Ultra Search database. A remote crawler profile is identified by the hostname. The profile includes the cache, log, and mail directories that the remote crawler shares with the database machine. "
    The Remote Crawler Profiles Page, however, displays only remote crawlers already defined and the page seems to be used just for editing the porfiles of these defined remote crawlers.
    My questions:
    (1) How do I create the remote crawlers and defines the profiles in the first place?
    (2) Where can I find more documentation on remote crawlers?
    (3) Once the remote crawlers are set up, how do I specify the file URLs for each remote crawler?
    (4) With US9.02 or 9.2, does remote crawler work the same as in 1.0.3, or are there any enhancements?
    Thanks!

  • I have a mini iPad and cannot send any messages to no one other than people which have the I phone why can't I send to there phones

    I have a mini iPad and cannot send messages to any one except people with a I phone can you tell me why I can't send to other phones

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    Fix Can’t Sign Into FaceTime or iMessage iOS 7
    http://ipadtutr.com/fix-login-facetime-imessage-ios-7/
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457
    Send an iMessage as a Text Message Instead with a Quick Tap & Hold
    http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • How can we open a new instance of Firefox without URL bar and any other control (except PREV, NEXT and RELOAD)?

    Dear Volunteers,
    I am looking for a solution for Firefox Win App and Mobile Apps where on click of a button from the website page, we should be able to launch a new instance of firefox instance (like a popup box) with following features:
    a. It SHOULD NOT have any URL bar to display.
    b. It SHOULD NOT show any plug-ins or any other functionality except Previous, Next and Reload.
    c. This instance of firefox should always be on-top of all other application.
    Please advise, how firefox can be customized to offer in all platforms by default.
    With lot of hope from this volunteer community,
    Rajiv

    You would need your visitors to install some kind of add-on, since web pages do not have permission to block the display of the page address and users do not need to allow a new window to be modal and block other Firefox windows, much less other OS windows.
    Over the years, people have developed extensions for kiosk-style displays. You could investigate those for ideas.

  • I bought a pdf book last year and had no problem reading it for a few months then all of a sudden I could no longer open it and to this day. Any other pdf download off internet I can still open and read, except for that particular book. Operating system i

    I bought a pdf book last year and had no problem reading it for a few months then all of a sudden I could no longer open it and to this day. Any other pdf download off internet I can still open and read, except for that particular book. Operating system is Windows 7 Home Premium, Adobe Reader XI 11.0.07.  When trying to open file I get msg "You did'nt login or your session has expired. Please log in to read this document for the first time". (Like I said I have read it before). So I log in but that prompts me to give the name of the file I want to export or convert to Word or something else, which is not what I want to do of course. I have not purchased any service from Adobe or Acrobat as I only need to read. Thanks for your help..

    Thank you for your reply. Operating system is Windows 7 Home Premium, Adobe Reader XI 11.0.07.  When trying to open file I get msg "You did'nt login or your session has expired. Please log in to read this document for the first time". (Like I said I have read it before). So I log in but that prompts me to give the name of the file I want to export or convert to Word or something else, which is not what I want to do of course. I have not purchased any service from Adobe or Acrobat as I only need to read. Thanks for your help.

  • Hello everyone, Very recently itunes on my windows computer does not let me access any items in my Library except for "Apps" and "Ringtones". When I click on any other items it flashes the redcircle meaning forbidden".

    Hello everyone, Very recently itunes on my windows computer does not let me access any items in my Library except for "Apps" and "Ringtones". When I click on any other items it flashes the redcircle meaning forbidden".
    When I connect my iPhone or iPad I can see every items on them but not on the iTunes Library.
    They sync fine with iTunes.
    I browse all the menus in iTunes but cannot find any clues to what I have done for it to happen. It worked fine previously.
    Thanks for any suggestion.

    You should really read the manual.
    "How do you restore from backup? "
    Restore.  When given the choice, choose to use backup.
    "And how can I check to see if the pics and videos are on my computer somewhere first??"
    They would only be where you put them.  What program did you use to import them?  Pics/vids taken with ipod are not part of the sync process at all.  You should be importing them just as you would with any digital camera.
    If you did not import them, then they are not on your computer.

  • Does anyone know when infinity blade 2 will be on any other app store except the US? south africa to be specific...

    does anyone know when infinity blade 2 will be on any other app store except the US? south africa to be specific...

    Apple Support Communities Use Agreement
    2. Submissions
    Stay on topic. Apple Support Communities is here to help people use Apple products and technologies more effectively. Unless otherwise noted, do not add Submissions about nontechnical topics, including:
    Speculations or rumors about unannounced products.
    Discussions of Apple policies or procedures or speculation on Apple decisions.

Maybe you are looking for

  • How do I set a default page size, orientation, and printer for a particular document in Pages?

    I have a simple label document in Pages which I print to my label printer. The label is 1.49 x 3.47 inches and needs to print in Landscape, and it needs to print to my Dymo label printer. How do I set up the Page Setup or Print Setup so it defaults t

  • Share Individual Folders & Retain Directory Structure

    Hello. I'm currently sharing an external raid array on my Mac Mini running OSX Server. My company's files are stored here, split up by LLC, then department. I want to create users/user groups to give limited access to certain areas. However, despite

  • Iweb 08 and email links

    I've uploaded my site to dogbark and now the email link ( where you say "email me") on each page won't work. Apparently ,the email address box is coming up on the hose at an html code and not an email link. However, when I hyper linked "email me" I l

  • Help!! How can I get my timemachine to work with motorola router

    I just had comcast installed in home.  Apple router is not working with motorola sb510u

  • Delivery creation using VL10C

    I am currently using VL10C to create a single delivery for mutliple sales orders and it is working well. The users want to be able to view the delivery prior to the number being assigned to ensure that it has created as expected. There are two option