Error Messages In Java
Contents |
To contact Oracle Corporate Headquarters from anywhere in the world: 1.650.506.7000. To get technical support in the United States: 1.800.633.0738.
JComponent Class Using Text Components Text Component Features The Text Component API How to Use Various Components How to Make Applets How to Use Buttons, Check Boxes, and Radio Buttons How to Use the ButtonGroup Component How java update to Use Color Choosers How to Use Combo Boxes How to Make Dialogs java error messages list How to Use Editor Panes and Text Panes How to Use File Choosers How to Use Formatted Text Fields How to java error handling Make Frames (Main Windows) How to Use Internal Frames How to Use Labels How to Use Layered Panes How to Use Lists How to Use Menus How to Use Panels How to Use Password https://java.com/en/download/help/index_error.xml Fields How to Use Progress Bars How to Use Root Panes How to Use Scroll Panes How to Use Separators How to Use Sliders How to Use Spinners How to Use Split Panes How to Use Tabbed Panes How to Use Tables How to Use Text Areas How to Use Text Fields How to Use Tool Bars How to Use Tool Tips How to Use Trees How to Use https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html HTML in Swing Components How to Use Models How to Use Icons How to Use Borders Solving Common Component Problems Trail: Creating a GUI With JFC/Swing Lesson: Using Swing Components Section: How to Use Various Components Home Page > Creating a GUI With JFC/Swing > Using Swing Components «Previous•Trail•Next» How to Make Dialogs A Dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window. Most Dialogs present an error message or warning to a user, but Dialogs can present images, directory trees, or just about anything compatible with the main Swing Application that manages them. For convenience, several Swing component classes can directly instantiate and display dialogs. To create simple, standard dialogs, you use the JOptionPane class. The ProgressMonitor class can put up a dialog that shows the progress of an operation. Two other classes, JColorChooser and JFileChooser, also supply standard dialogs. To bring up a print dialog, you can use the Printing API. To create a custom dialog, use the JDialog class directly. The code for simple dialogs can be minimal. For example, here is an informational dialog: Here is the code that creates and shows it: JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be gree
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the http://stackoverflow.com/questions/446663/best-way-to-define-error-codes-strings-in-java company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Best way to define error codes/strings in Java? up vote 75 down vote favorite 47 I am writing a web error messages service in Java, and I am trying to figure out the best way to define error codes and their associated error strings. I need to have a numerical error code and an error string grouped together. Both the error code and error string will be sent to the client accessing the web service. For example, when a SQLException occurs, I might want to do the following: // Example: errorCode = 1, // errorString java error messages = "There was a problem accessing the database." throw new SomeWebServiceException(errorCode, errorString); The client program might be shown the message: "Error #1 has occured: There was a problem accessing the database." My first thought was to used an Enum of the error codes and override the toString methods to return the error strings. Here is what I came up with: public enum Errors { DATABASE { @Override public String toString() { return "A database error has occured."; } }, DUPLICATE_USER { @Override public String toString() { return "This user already exists."; } }, // more errors follow } My question is: Is there a better way to do this? I would prefer an solution in code, rather than reading from an external file. I am using Javadoc for this project, and being able to document the error codes in-line and have them automatically update in the documentation would be helpful. java enums share|improve this question asked Jan 15 '09 at 13:11 William Brendel 21.2k75976 Late comment but worth a mention I thing... 1) Do you really need error codes here in the exception? See blabla999 answer below. 2) You should be careful passing too much error information back to the user. Useful error info should be written to server logs but the client should be tol