Exception messages....how do YOU eat yours??

Exception Messages - For user or developer?
Summary
When catching Exceptions, is/should it be necessary to look at the message String for deciding what action should be taken or is the message just for humans?
What is the generally accepted use of Exception messages - user messages, or for deveopers and program parsing?
Details
Exceptions generally contain some kind of 'useful' message.
As we are developing our programs we, as developers, might be able to use this message to help diagnose problems.
But once we've finished development and come to deploy our program we will, of course, be catching all possible Exceptions so that the user does not get thrown out of the program in a very undignified manner.
When catching these Exceptions, what 'should' be done with it?
Wrap it up as a neat little Error message for the user?
Or are they there for programs to 'read' themselves and decide what to do next depending upon the potentially dynamic message String?
thanks,
John
([email protected])

In addition, when you start thinking about parsing exception messages to further determine the facts behind the exception, it makes me wonder if you aren't forgetting to check your variables to further determine the problem, and also to take advantage of defining your own custom exceptions to further refine your handling of the errors that are unique to your program.
Let me give a cheesy (and purely conceptual) example to describe what I mean.
Your program is simulating cooking pizza's, let's say. At the end of the baking process, you catch an array index out of bounds exception as a basic beginning.
Now, upon finding something unexpected wrong with the array of pizzas that you were expecting from the oven (within the catch block), you check for the conditions that help you refine your understanding of what went wrong.
So, you test 'was the array null?' ...which means nothing at all came out of the oven, in which case you throw your custom "OvenWayToHotException", with a warning for the cook to turn down the heat. If the array was NOT null, but just had less values than you expected ...you can then throw your "PizzaLeftBehindInOvenException", with a warning for the cashier to go check the oven because someone forgot a pizza inside. These further refined exceptions are then thrown up the chain to the portion of your code that presumed to cook the pizzas properly before giving them to the customer.
In the end, the message to either �check the oven for missing pizzas� or �apologize to the customer while they wait for you to redo their whole order� will be a lot more informational than �ArrayIndexOutOfBoundsException at method cookPizzas()�
I realize this might be a cheesy example, but maybe it demonstrates a technique for using base exceptions as a beginning point for determining programmatically what went wrong, and then handling it from there. Further inspection of variables is more likely how your program will figure out what went wrong rather than parsing the message in the rare case that it contains unique information. You, who wrote the program, usually know exactly what it means when certain groups of variables are found in certain states. Exceptions are a way to avoid doing a bunch of unnecessary tests until you get an indication that these tests are actually required in the first place.
Of course, having said that, you are also free to be creative when you design code ...so if what you are doing works better than any other approach you can think of ...then using any idea you can cobble together is probably better than throwing the program in the trash bin, wouldn't you say?

Similar Messages

  • On a MacBook, in Messages, how do you prevent your IMs from being sent as texts?

    In Messages, how do you prevent your messages from being sent as texts?

    Shootist007 wrote:
    Not sure how and why this type of thing started but it seems every program you install these days likes to start part of itself when the system starts.
    That started with Lion and progresses with the hillside feline. Ever since that pair got a personality disorder and can't make up their mind whether they're computers or phones, the world went to the dogs.  "Always on" paradigm my azz!

  • How do you add your contact picture to a text message?

    I want to be able to see my contact pictures whenever I text someone from my contacts list. How do you put your contact pictures on a text message for iPhone 6? I can see my contacts pictures when I send/receive a group text but not an individual text. Is this feature equip for apple phones? Thank you!!!

    bmm243 wrote:
    Is this feature equip for apple phones?
    No.

  • How do you keep your message from appearring on a locked screen

    how do you keep your message from appearring on a locked screen

    Go to SETTINGS --> NOTIFICATIONS --> MESSAGES
    Change "View in lock screen" to OFF
    That should sort it for you.

  • How do you get your text messages to not show on the screen when they come in

    How do you get your text messages to show on the screen when then come in?  My iphone 3s would just say the persons name and text message.  This says the persons name and the whole message

    Settings > Notifications > Messages > Show Preview - Turn to OFF

  • HT4061 How do you change your phone number than is in your iPad and replace it with right one to receive and send messages?

    How do you change your phone number in your iPad messages and replace it with another number. In order to send and receive messages to the correct phone number?

    It's best to use an email address on the iPad.
    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/
    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 do you export your movie using idvd? I keep getting error messages and notices that I do not have enough space to transfer to a dvd.

    How do you export your movie using idvd? I keep getting error messages and notices that I do not have enough space to transfer to a dvd.

    Can you give us the steps to re-create the problem, and the exact wording of the error message you are getting please.

  • How can you get your submit buttons to be a single click instead of the default double click?  (The

    How can you get your submit buttons on the quiz template to be a single click instead of the default double click?  (The option to choose double click or not is not showing in properties for this).

    Hmmm... Submit button doesn't need a double click at all. Maybe you are talking about the two-step process? When you click on Submit, the feedback appears with the message to click anywhere or press Y. Is that what you are talking about? If you are talking about a real double-click, something must be wrong in your file. And which version are you using?
    http://blog.lilybiri.com/question-question-slides-in-captivate
    Lilybiri

  • How do you change your apple id on your iphone 5

    how do you change your apple id on your iphone 5. I also increased storage and cannot update to latest software upgrade! ANNOYING!!!!
    Yes, I logged in and out of the Ap Store and it is correct on that end. I have signed in on my PC too and connected cell. I am out of tactics to resolve! Please help!

    If your phone is signed into an old ID and you are trying to change it to an updated version of the old ID, do the following:
    Make sure you are signed into iMessage and FaceTime with your current ID.  If they are signed into the old ID, go to Settings>Messages>Send & Receive and Settings>FaceTime, tap the ID, sign out, then sign back in with your current ID.
    Then temporarily recreate the old ID by going to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  (You should not have to verify the old email account so it doesn’t matter if you no longer have access to it.)  Now go to Settings>iCloud, turn off Find My iDevice and enter your current password when prompted (even though it prompts you for the password for your old ID).  When finished goThen go to Settings>iCloud, tap Sign Out (or Delete Account if you are not running iOS 8) and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address back to the way it was.  Now you can go to Settings>iCloud and sign back in with your current iCloud ID and password (your data will download back to your device).

  • How do you read your favorite feeds?

    Hi! This is my very first post on Arch forums.
    I'm wondering about how do you read your favorite feeds? Which software do you use and why (what kind of features).
    I'm more interested in finding a little software that uses the system tray.
    Yet I'm also curious about just how does, those who utilize RSS, do it.
    Personally I've used YARSSR, which is exactly what I want, except for few problems..
    On Ubuntu it used to be as easy as make, make install (having build-essenial installed). On Debian 4.0 stable it is in the stable repos, so it was even easier. On Arch it's not in any of the repos nor AUR and make, make install didn't work:
    # yarssr
    bash: yarssr: command not found
    # /usr/local/bin/yarssr
    Can't locate Gnome2.pm in @INC (@INC contains: /usr/local/lib/yarssr /usr/lib/perl5/5.8.8/i686-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0/i686-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at /usr/local/lib/yarssr/Yarssr.pm line 3.
    BEGIN failed--compilation aborted at /usr/local/lib/yarssr/Yarssr.pm line 3.
    Compilation failed in require at /usr/local/bin/yarssr line 13.
    BEGIN failed--compilation aborted at /usr/local/bin/yarssr line 13.
    I'd love to understand what's going on. How to install it right.
    Anyhow, it's far from perfect anyway. It's the single thing that is not working so perfectly on my Debian as it should. Uses way too much CPU, sometimes stays trying to update and never does update nor allow forced updates, no quitting, etc..
    I also use Google Reader, which is great to read many feeds and manage them, etc.
    All I want is a little applet (maybe GNOME applet?) that gives me quick glimpse of my top favorite feeds, without using my browser nor launching a full-functional aggregator.
    Last edited by UnbreakableMJ (2007-05-24 14:43:38)

    UnbreakableMJ wrote:
    iphitus wrote:
    have used newsgator, planet, own scripts, google reader, akregator, blam, raggle.
    currently using snownews.
    so far, none of them really suit how i want to read my news.
    James
    Hi James.
    I'd like to know how you want to read your news
    i'd prefer a cli frontend, web front would be bonus (river of news style).
    snownews is good, just needs a few tweaks, some ui ones, and the main one being:
    often i dont get to read news for a few days straight, so i'd like something i can put in cron and it'll update, and log the news for a few days straight, so when i get back it's all there. this generally limits me to one of the web clients, i dont know any desktop apps that do this.
    i might write up an app to do this someday
    as for your yassr problem, pacman -S gnome-perl?
    James
    Last edited by iphitus (2007-05-25 11:32:57)

  • How do you change your security questions for your Apple ID ?

    How do you change your security questions under your Apple ID

    How to reset your Apple ID security questions.
    Go to appleid.apple.com, click on the blue button that says 'Manage Your Apple ID'.
    Log in with your Apple ID and password. (If you have forgotten your Apple ID password, go to iforgot.apple.com first to reset your password with a password recovery email)
    Go to the Password & Security section on the left side, and click on the link underneath the security questions that says 'Forgot your answers? Send reset security info email to [email]'.  This will generate an automated e-mail that will allow you to reset your security questions.
    If that doesn't work, or  there is no rescue email link available, then click on 'Temporary Support PIN' that is in the bottom left side, and generate a 4-digit PIN for the Apple Account Security Advisor you will be contacting later.
    Next, go to https://getsupport.apple.com
    (If you see a message that says 'There are no products registered to this Apple ID, simply click on 'See all products and services')
    Choose 'More Products & Services', then 'Apple ID'.
    A new page will open.
    Choose 'Other Apple ID Topics', then 'Forgotten Apple ID Security Questions'.
    Click the blue 'Continue' button.
    Select the contact option that suits your needs best.

  • How do you sync your iphone to your itunes without losing your contacts

    Just go an iphone 4. How do you sync your phone to iTunes without it erasing all your contacts and messages etc. I did yesterday and it erased everything. I had to go back to AT&T to get all my contacts and photos back. I backed up my iphone but I don't know where to go from there...

    http://support.apple.com/kb/HT1751

  • How do you find your blocked numbers in Contacts or on your iphone?

    How do you find your blocked numbers in Contacts or on your iphone?
    Is there a way to get a list of the blocked numbers?

    Hey jeff work,
    Thanks for using Apple Support Communities.
    This article should be exactly what you are looking for.
    iOS 7: Understanding call and message blocking
    http://support.apple.com/kb/ht5845
    You can review your blocked list through one of the following locations:
    Settings > Phone > Blocked
    Have a nice day,
    Mario

  • How do you get your old back ups back

    how do you get your old back ups back

    Typically iCloud and iTunes only save the latest backup. In reality, when you subsequently backup, the last backup is modified with the changes and you only have one backup. The except seems to be if you restore from backup it appears that that backup is retained.
    Go to Settings>iCloud>Storage and Backup>Manage Storage and to iTunes>Preferences>Devices and see if more than one backup is listed.

  • HT1766 how do you get your phone to turn back on after you tried to restore it and it wouldn't?

    how do you get your phone to turn completely back on after you tried to restore it and it wouldn't restore?

    Hello Brittany Jo,
    Welcome to the Apple Support Communities. If you have issues with the phone restoring, the following articles will assist with options on how to fix the issue.
    iOS: Unable to update or restore
    http://support.apple.com/kb/HT1808
    iOS: Resolving update and restore alert messages
    http://support.apple.com/kb/ts1275
    Regards,
    -Norm G.

Maybe you are looking for

  • Credit and debit enteries ADC

    HI all      As per excise law 4% cenvat credit is of additional customs duty and note additional excise duty (Goods of Special Importance) i.e. AED (GSI).       So we have to take credit as well as make debit entries in ADC head and note AED(GSI). So

  • JFileChooser doubt

    Hi, I was wondering how could i get the complete file path from my JFileChooser, instead of getting only the file name...... i used the .getSelectedFile().getName() methods and I only got the file's name.... does anyone know how to get the filepath a

  • Telephone Number Extensions

    How do you enter telephone number extensions to the phone numbers in your contacts list in Outlook so it will automatically sync to your i-phone?

  • Laptop doesn't detect driver for Pixma iP100 printer.

    Have Pixma iP 100 installed on Toshiba A665 laptop. Was working fine. Then upgraded to Windows-8 after which computer failed to recognize printer. Have down loaded Wx 8 driver from Canon website to no avail. Have uninstalled and re-installed still to

  • Problème de commande sur iPhoto

    Après la réalisation d'un livre album, je souhaite passer une commande pour l'imprimer mais mon iPhoto ne répond pas.