Defensive programming - error labels

How do I use labels to point out where an error has occured? Right now I have a simple JFrame interface with radio buttons and text fields. What I want are labels that appear next to these items if an error occurs at any. For example, a radio button might not have been selected when the 'proceed' button is pressed, so a label will point this out.
I have put in the labels, I just need to know how to link these to the code. In other words, I need them to be not visible by default and set to visible when en error occurs. Also, will throwing an exception terminate the method call? (I should know this)

We did something similar to denote required fields.
Every field would have an associated JLabel. Each label consists of an icon + text. For required fields, the icon was a 5 pixel red asterisk. For the non-required fields, we used a blank, transparent gif that was also 5 pixels wide. If the field was required, the required icon was "turned on" (the red asterisk icon was set on the label), and if the field was not required or already filled in, the required icon was "turned off" (the blank icon set on the label).
The icons were of the same width to prevent "shifting" as the indicator would go on/off, and so that the text of the labels would be left-aligned with neighboring labels above or below regardless of the indicator being on/off.

Similar Messages

  • Contract and defensive programming

    I'm exploring the differences between Contract and Defensive programming. I'm seeking any comments from the community on the subject of these two apparently opposing paradigms. (Or am I wrong? Do they oppose?)
    Contract Programming, or Design by contract, is a programming paradigm whereby classes define their behavior and interplay by "contracts" which are defined in terms of pre-conditions, post conditions and class invariants. In this paradigm, the code must "fail hard", and resist verifying that the contract conditions are met.
    Defensive programming is an opposite strategy. In this paradigm, the assumption is made that the pre conditions of a method call ought to be tested within the method for assurance. This can lead to extra development and a potential veiling of errors elsewhere, such was where and how the call is made.
    My question is, which of these is the preferred method, or ideology of development and why?
    Thanks for any feedback and links to external sources which may be helpful.

    Just asking a clarifying question:
    I'm not sure of the difference between the 2, and my understanding is Java doesn't 'directly' support Design by Contract. I have only
    seen this in Eiffel (in school), but my question, aren't manually coded 'precondition checks' the way to support Design by Contract in Java?
    lance.walton wrote>
    <The important difference, which you've kind of alluded to, is that defensive programming tries to consider what contract violations might occur and provide <strategies for dealing with this. The result is more code that will ideally never be executed. This clutters the intent of what you're trying to achieve as well <as probably introduce more defects because of the clutter. It also suggests that the client code might make mistakes that you can help it with.
    <
    <Even if you don't do Design by Contract (hard to do properly in Java), I would not do defensive programming. It allows sloppy client code, and that <allowance then has to be maintained, which will get harder and harder as your code evolves until you start talking about a rewrite because it's such a <mess.
    If you want to protect yourself against poor client code, use precondition checks.

  • Defensive programming vs exception handling

    Hi
    im new to java programming and having problems getting my head around defensive programming vs exception handling.
    i've read in my uni books about design by contract and the idea of defensive programming but im having problems with it.
    so say i write the code.
    String container = //some value
    if (container.equals.("")) // so if i am looking for a value and find a empty String
       throw new // a custom exception i have made for this error.
    else
       //do whatever i had planned with a non-empty String
    }is this Defensive programming or exception handling. Or am i complete of base.
    thanks

    jverd wrote:
    JustSomeGuy wrote:
    Don't fall into the trap of saying "Meh, the exception will handle it". If you can forsee something easily being a problem, and it can be controlled, then control it. Save the exception handling for those things you don't forsee and those you can't control. I disagree. Or at least, I disagree with what I think you're saying.
    For instance, if null is not a valid argument, then document it, and don't waste code defending against it. Either throw an explicit IllegalArgumentException, or let the NPE be thrown.
    And absolutely under no circumstances should you ever write code that will deliberately lead to an exception, Eh? If an exceptional condition occurs, you should delibrately throw an exception. Consider if you will the following code snippet
    import java.io.*;
    class ExceptionExample {
        public static void main(String[] args)
            throws IOException {
            if (args.length == 0) {
                System.out.println("Must give filename as first arg.");
                return;
            FileInputStream in;
            try {
                in = new FileInputStream(args[0]);
            catch (FileNotFoundException e) {
                System.out.println("Can't find file: " + args[0]);
                return;
            int ch;
            while ((ch = in.read()) != -1) {
                System.out.print((char) ch);
            System.out.println();
            in.close();
    } What I was saying in the first part is shown with the following part of the above code
    if (args.length == 0) {
       System.out.println("Must give filename as first arg.");
       return;
    } Would the exception handler that follows this peice of code have taken care of that? Sure! Would it be the best choice to just let the exception handler do it? No way no how!
    It is easy to forsee someone forgetting or not realizing they need to add the filename as an arg and it can be controlled, so in this and most cases just like it the best choice is to either inform the user with a more specific statement than could be used in the exceptionhandler and do nothing or fix it yourself like for instance by using a default filename.
    What I meant by deliberately throwing an exception can be illustrated with this small portion of my code above
    int ch;
    while ((ch = in.read()) != -1) {
        System.out.print((char) ch);
    } A -1 to mark the EOF is expected and reaching the EOF is expected. There is absolutely nothing abnormal about this, so it should not be handled by an exception. But far to often I have seen novice and especially "think they know it all novices" use an exception in place of exactly this. They know the file will end, they know they must do something about that, but instead of doing it right they just set it up so an exception will be thrown and they can just handle it in the exceptionhandler. This is what I meant by deliberately throwing exceptions, in that an exception must be thrown in order for their program to work as intended. Bad, very bad.
    Now that I have provided an example and further clarified my position do you still disagree? I can't imagine you would, so if you do I would be very interested in getting some further insight into your reasoning.
    JSG

  • Is defensive programming out?

    Hi,
    I wondered if I am a naturally talented software tester, because on trying some random software I easily find ways to make it segfault.
    Two examples from today include rosegarden and kazehakase.
    rosegarden, default configuration:
    Start it, doubleclick on the first measure, choose menu "segment" -> "new layer", click the undo button, enjoy segfault.
    kazehakase, default configuration:
    Start it, choose menu "view" -> "ui level" -> "medium" or "expert", choose menu "view" -> "view page source" while no tab is open (as it is with default config on first start), enjoy segfault.
    So first kazehakase: Yes, I know it is a very early version. But I can live with missing functionality like "view page source" doing nothing. The problem is crashing on issueing such command. Without looking at the code I bet this is a null pointer (because there is no page displayed) of which the developer thought "oh, this probably won't ever be null".
    Next is rosegarden which wants to be "professional".
    I believe this bug with "undo" to be similar to the one in kolourpaint (start kolourpaint, choose text tool and write a letter, press strg+a, strg+z, this should be fixed, but at least now not in the repos.). Maybe it's a problem in qt in general or a problem with implementing "undo" in general. I don't care.
    When implementing an undo function I would be EXTREMELY careful to what happens in this functions.
    You have to be ready to undo ANYTHING that the user can possibly do in your program which is hell of a lot.
    In these programs people apparently didn't use defensive programming: I can see the programmer sitting there and think about how to undo several things but not how to handle something coming into his undo function that it cannot undo.
    I also believe plasma from KDE to crash so much instead of displaying an error message because of that.
    The question I ask myself is: Why do I see so many segfaults and so few error messages?
    Is it time for a kernel API to inform the application that it segfaulted and give it a chance to recover, maybe even with user intervention?
    Last edited by Cdh (2010-06-27 20:43:51)

    bernarcher wrote:
    I think defensive programming, even "simple" exception handling, never was widely used. It is by no means trivial and tends to bloat the code, esp. in languages with no exception handling mechanisms built in, like C for instance.
    Even using languages which do provide fairly good mechanisms for exception handling (like e.g. Eiffel, or D) it is difficult to catch edge cases in a meaningful way (other than simply finishing program execution). More often than not exceptions do not occur locally to the program part which really needs to handle the situation. And if they do they lead to more or less combinatorial explosion if not thoroughly planned. Thus, making a programm foolproof from start as "defensive programming" mandates is a tremendous effort (and not overly exciting to do).
    Even if you try to handle system signals, things tend to be involved and complicated. Just have a look at theSignal Concepts in the Open Group  Base Specification. Or have a look at man signal and related man pages.
    This is not to state defensive programming to be fruitless. But the efforts in time (and money) are most often not taken. You can't easily show built-in defenses. Being able to get a program "just running" and showing some effects appears far more exciting.
    It is like thorough testing (beyond running a unit test suite), and documenting (both software and user sides) - most desirable, but not many want to really do the works.
    Well said. I can't really elaborate on this but I'd have to wholeheartedly agree.
    (Sorry I can't elaborate I whenever i'm coding something thats one of the few things I try to look out for).
    Last edited by Ari'osika (2010-06-28 09:49:05)

  • Error:  "Could not complete your request because of a program error" (photoshop CS2 9.0.2 on MAC OSX

    Today I started my program (photoshop CS2 9.0.2) and opened a JPG file. When I went to print the file the program crashed and closed. When I restarted the program and went to open the file I got this error message, "Could not complete your request because of a program error".
    I have tried several different file types/sizes and all result in the same error message since the program crashed. It will not open any file I try to open. As I indicated above I am using Photoshop CS2 9.0.2 it is on a MAC with OSX 10.4.11.
    I called Adobe and the Rep directed me to Tech Note 331307 and told me to Re-create the Photoshop preferences files. Which I did and restarted the program, but when I tried to open a file (any file) I still get the same error message so it doesn't appear to be the preferences.
    Does anyone have any info as to what the problem may be and how to correct it.
    Thanks

    Thanks for the response. OK... This is the first day I have been able to get back to the problem.
    My system I am running Photoshop on is a Power Mac G4, AGP Graphics ATY Rage 128Pro chip set 16MB VRAM LCD 1280x1024 32-bit color, 500MHz, 1.75GB of memory, 1 MB L2 Cache, 100 MHz Bus Speed. I had installed the latest security update and repaired the permissions the day the problem started.
    Now to day I started the system and went in and created a Guest Account. I logged into the guest account and started Photoshop. Low and behold it worked just fine. So I logged out of guest and logged into my main user account And started Photoshop. Wouldn't you know it.... It works just fine. I can open any file I want with now problems.
    I got to thinking after I had done all of this that I wished I had tried to open a file in Photoshop today prior to creating the guest account to see if it still had the problem in my main user account.
    I did not change anything else on the system and all seems to work fine now. So at his point I am really not sure what the problem was.
    Again thanks for taking the time to respond to this issue.

  • Photoshop CS2 (program error msg)... Help please!!

    I have installed the full creative suite 2 on my new iMac. everything works fine except photoshop?!!?
    Illustrator works great, In-Design works great, But when i try to open a file or create a new page in PS it tells me "Could not create document because of a program error"???? ***?
    I had a previous version of CS and it worked fine for one day, then that started happening. I installed the CS2 trial version, and it would still give me the same error msg. I erased everything and installed the new CS2 (photoshop, illustrator , in-design and acrobat). It still gives me the same darn msg.???
    Any help would be greatly appreciated!
    thanks

    See the Adobe Knowledge Base document"Error 'Could not complete your request...' or 'Could not create a new document...' (Photoshop CS2 on Mac OS X v10.4)"
    I suggest whenever you have problems with third-party applications, the first place to start troubleshooting is with the application's documentation, then vendor's web site. Usually their sites have FAQs, lists of known bugs, or application-specific forums similar to these Discussions. Sometimes, unlike the Apple Discussions, the questions are even answered by employees of the vendor.
    The document cited above was found in 10 seconds by searching the Adobe support site.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X

  • PhotoShop CS2 "Program Error" when printing

    I am posting this to the Adobe Forums as well, but thought someone here might have some ideas. am having an intermittent problem printing from PhotoShop CS2 to an Epson 9800. When printing large files (200 MB average) to the Epson, PhotoShop will spool the job, taking about 50% longer than normal, and when complete, displays the following message..."The file XXXX.tif could not be printed because of a program error" No job ever gets to the print que. This happens about 80% of the time when printing. Quitting and restarting PhotoShop generally fixes the problem, and the file can be printed from another computer without issue, so this is not file specific. I have 8GB of RAM installed and PhotoShop running under 100% available memory, cache level at 8, with a dedicated 180GB scratch disk. Memory should NOT be the problem, though I do often have the full layered version of the file open in the background (I am printing from a flattened copy. I have observed that the problem is less likely to occur if no other files are open. I have a second G5 with the exact same software setup (OS, Print Driver and PhotoShop down to the decimal version #) that works perfectly every time. I have run all of the System utilities (Repair Permissions, FSCK, etc), reset the OSX printing system, reset PS preferences, trashed and re installed CS, as well as the Epson printer driver, all with no success. Any other trouble shooting ideas would be greatly appreciated. I would love to avoid a System reinstall.

    See the Adobe Knowledge Base document"Error 'Could not complete your request...' or 'Could not create a new document...' (Photoshop CS2 on Mac OS X v10.4)"
    I suggest whenever you have problems with third-party applications, the first place to start troubleshooting is with the application's documentation, then vendor's web site. Usually their sites have FAQs, lists of known bugs, or application-specific forums similar to these Discussions. Sometimes, unlike the Apple Discussions, the questions are even answered by employees of the vendor.
    The document cited above was found in 10 seconds by searching the Adobe support site.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X

  • ESYU: ENCOIN: ECO Open Interface Program 사용시 error 발생 문제

    Purpose
    Oracle Engineering - Version: 11.5.6
    ECOs import를 위해 ECO Open Interface(ENCOIN module)을 사용할 때,
    Interface program이 아래와 같은 error를 발생시킨다.
    "ORACLE error 6550 in FDPSTP
    Cause: FDPSTP failed due to ORA-06550: line 1, column 7:
    PLS-00201: identifier 'ENG_LAUNCH_ECO_OI_PK.ENG_LAUNCH_IMPORT' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored"
    어떻게 ENCOIN: ECO Open Interface program을 사용해야 하는지 알아본다.
    Solution
    ECOs를 importing 하기 위해 ECO open interface를 사용하는 것은 권장하지도 않고,
    support 되지도 않는다.
    ECO data를 load 하기 위해 ECO open interface를 사용하는 대신 ECO Business Object
    이나 ECO form을 사용해야 한다.
    ECO Business Object 사용에 대한 보다 상세한 내용은 Manufacturing and Open Interfaces
    Manual을 참조한다.
    또한 Note 132874.1에 설명되어져 있는 ECOBOI module을 이용하도록 한다.
    만일 당신의 application version이 11.5.9 이상이라면 ENCOIN module(ECO Open Interface)는
    ECO details를 import 하기 위해 사용될 수 있고, ENCOIN은 11.5.9 이상의 version에서만
    지원이 된다.
    Reference
    Note 392011.1

  • "Program Error"  While trying to print in PSE 9

    Download and installed updates to PSE 9.0, Now 9.03. While in PSE mode I can no longer print images to Epson Photo R2880 or HP J4680. I can print to both printers using HP Media Smart Photo application, but if I attempt to print from PS Elements I get the following "could not print (image title) because of program error". I have since uninstalled the upgrade to PSE 9.03, I have also  done a system restore all to no avail. I still can't print while in PSE. Any experience with this? Any resolution ? Help !!!

    Please post Photoshop Elements related queries over at
    http://forums.adobe.com/community/photoshop_elements

  • Photoshop CS2 not working after 10.6.7 update? program error!

    Could not complete your request because of a program error. I opened an image RGB and wanted to save it as a CMYK.
    Save as and entered new name... thats it! Then the error popped up. The only thing that has changed is the update!
    Please help.

    If you updated to 10.6.7 then you should (go to your Apple menu at the far left and) check for updates.
    There was a problem with some types of Fonts that has been fixed by the Snow Leopard Font update:
    http://support.apple.com/kb/DL1377
    However, always wait after an OS update (true of Windows too) and see if it causes any problems with 3rd-party software, etc. - PRIOR to updating your system   And always, always have a full, known-good backup before you update. Especially for any computer that is used for business purposes !
    Last but definitely not least, you should know that Adobe CS2 is a Power-PC only application (circa G4 and G5 processors, before Apple moved to Intel processors), and requires Rosetta (PowerPC emulation).
    So you should consider any CS2 application running at all, as fairly miraculous.
    CS3 was released four years ago, and provided the first Intel-native ("Universal Binary") versions of the CS-suite applications.
    Mac OS 10.6 only runs on Intel-based Macs (ie: Intel processor required).
    If you are using Photoshop CS2 for any revenue-generating purposes, then it is (and was) incumbent upon you to properly allocate and budget for
    upgrades and you should - nay, must - be running a more current version of the software. If your budget does not allow for newer Adobe CS, then you should have kept a legacy system that can run an older Mac OS, and understand that your workflow is living on borrowed time - and you had best keep several old Macs that can still run an older Mac OS and run your CS2 natively.
    In no way shape or form is CS2 supported under Mac OS X 10.6 - certainly not in any official way by Adobe !
    You could also be irate about not being able to use your 8-track tape player in your brand new car. I'm exaggerating but not too much.
    Please read Adobe's response regarding CS3 (not CS2) and 10.6/Snow Leopard:
    http://blogs.adobe.com/jnack/2009/08/adobe_snow_leopard_faq.html
    With all of this in mind, you should know that your frustrations with Apple and the unsupported and not-recommended interaction of CS2 and 10.6 are misguided. Best of luck to you !

  • "Program error" When I click on the timeline/motion controls or try to export/save as my animation. PS CC late 2014

    I have been working on an animation for an online ad. The file is 300 by 250. It's about 24 seconds long. I had completed and saved my work as a GIF file. I also saved some static JPGs of the animation. Everything was still working at this point. Then I closed Photoshop and reopened the PSD file to export it to a different format, but when I clicked on the time-marker in the timeline window or tried to edit my animation, I got this error message: "could not complete your request because of a program error." Watch the following video to see exactly what happens:
    I'm running Adobe Photoshop CC November 2014. I'm working on a PSD file, 24 seconds long, 30 fps.
    I looked in my library/preferances/adobe folder for photoshop's error log file. This is the error in that file:
    2014:11:12 18:30:17 : /Volumes/workarea/PS_15_Mac_Daily_Retail/20140730.r.148/photoshop/main/photoshop/sources/ ULinkManager.cpp : 1380 : REQUIRE failed
    Thank you so much for reading this. It sucks to work so long on an ad and then have this happen for seemingly no reason. Please help if you can.

    Looks like issues with some linked smart objects... You could try and copy/ move the whole shebang to another location in the hopes that it either fixes the issue or PS completely forgets the linked files completely so you might relink/ replace them.
    Mylenium

  • Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help

    Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help with this, please.

    jpg does not support Layers.
    Just to make sure, what exactly do you mean by "stacking photos" and what do you want to achieve thereby?

  • I keep getting a message saying "Could not complete your request because of a program error"

    I keep getting a message saying ( Could not complete your request because of a program error??
    Does anyone know what this means or how to fix?

    blucoast,
    Can you please be more detailed? When are you getting this - what is causing it? Any specific tool or while starting Photoshop itself?
    Do you see an error number or error code or a report? Can you post that here?

  • Effects not working? "Could not complete your request because of a program error?"

    Hey guys&gals - I have always had this problem when working in RGB/CYMK modes - can anyone help me with that?
    More more importantly, now I am getting in in Grayscale mode as of this morning.
    I run Photoshop 6 V 13.1.2 x64 and just updated it this AM.
    Effects are crucial for my job, so I need this fixed asap!!
    I have tried the ctrl, alt, shift start up to no avail. Restarted, shutdown my PC as well.
    Please advise!
    Thanks,
    blaqgranitelaser

    Found the places I was supposed to - now what? Photoshop isn't crashing... doesn't give me any info other than a box saying "Could not complete your request because of a program error." And I have no choice but to click OK. This only happens when I try to use the layer effects in any color mode. Originally it was only in RGB/CMYK but now also happens in Grayscale.
    I'm not technologically savvy - I know what programs I use, but that is all.

  • Can't open file: "Could not complete your request because of a program error"

    I have a Photoshop file that suddenly won't open.  Last week I upgraded to CS5--the file had been created in CS3 prior to that.  When I try to open it, I receive this error message (in CS5): "Could not complete your request because of a program error."  I tried to open the same file in CS3; there, the file opens, but as soon as I try to do anything I get the same error message....which, annoyingly, re-appears the second I click "OK," so the only thing I can do in CS3 is force-quit.
    I've used Time Machine to retrieve versions of the file that were saved four days ago, seven days, and several weeks ago, and I get the same message every time.  Even on versions that were last saved with CS3 (before I installed CS5).
    Naturally, this is one of the most important files in my life right now....it's a 300 MB file that contains hundreds of layers and dozens of comps.  So the fact that I suddenly can't open it, after shelling out $1200 to upgrade to the latest and greatest Adobe has to offer, is, to say the least, distressing.
    Any advice will be appreciated.
    Thanks,
    TheWocky

    First thing I would do is investigate hard drive issues and the health of the OS.

Maybe you are looking for

  • Remove zeros in LOVs of BW Infoobjects on Webi report

    Dear Experts, My BW infoobjects(0GL_ACCOUNT) showing preceding zeros in the BI4.1 WEBI Prompts LOVs, so user don't want the zeros and they need only values and also they compare BEx analyzer with BO since BEx analyzer LOVs shows only values without z

  • HELP!!! ipod appears in my computer but not in itunes...

    i did what apple says to do but it wont work.... my dad connected it to the computer and itunes doesnt even pop up. so he disconnected it, opened itunes and connected it. it didnt show my ipod, yrt the ipod charges.... my dad pressed view and then he

  • Handling result form Stored Proc in java program

    Folks, I have a question on how to handle results from Stored Procedures with the java.sql API. I execute a stored proc from a java program using the statement: statement.execute(); where 'statement' is of type Statement. Then I get the results: Resu

  • Account Details page transaction link do not display anything

    Hi, I extended the TransactionTableVO to include new columns. Initially, whenever I click on the transaction link, I get an exception error. But I fixed it by commenting out functions that seem to overrride the original one (like setIrSalesOrder, set

  • Microphone for 5th Gen iPod

    I just purchased a new 5th generation iPod (Video) and everyone is talking about how great the recording quality is. I would like to get some sort of Mic so that I can record lectures and other things at school. Is there a Microphone out yet for the