KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > sendopts > CommandException


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.sendopts;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24
25 /** Signals that something is wrong when processing the command line arguments.
26  *
27  * @author Jaroslav Tulach
28  */

29 public final class CommandException extends Exception JavaDoc {
30     private final int exitCode;
31     private final String JavaDoc locMsg;
32     
33     /** Simple constructor for the CommandException to indicate that a
34      * processing error occurred. The provided <code>exitCode</code> represents
35      * the value to be usually send to as a return value to {@link System#exit}.
36      *
37      * @param exitCode the value, should be different than zero
38      */

39     public CommandException(int exitCode) {
40         this("Error code: " + exitCode, exitCode, null); // NOI18N
41
}
42
43     /** Creates new exception with a localised message assigned to it.
44      * @param exitCode exit code to report from the exception
45      * @param locMsg localised message
46      */

47     public CommandException(int exitCode, String JavaDoc locMsg) {
48         this("Error code: " + exitCode, exitCode, locMsg); // NOI18N
49
}
50     
51     
52     /** Creates a new instance of CommandException */
53     CommandException(String JavaDoc msg, int exitCode, String JavaDoc locMsg) {
54         super(msg);
55         this.exitCode = exitCode;
56         this.locMsg = locMsg;
57     }
58     /** Creates a new instance of CommandException */
59     CommandException(String JavaDoc msg, int exitCode) {
60         this(msg, exitCode, null);
61     }
62
63     /** Returns an exit code for this exception.
64      * @return integer exit code, zero if exited correctly
65      */

66     public int getExitCode() {
67         return exitCode;
68     }
69
70     /** Localized message describing the problem that is usually printed
71      * to the user.
72      */

73     public String JavaDoc getLocalizedMessage() {
74         if (locMsg != null) {
75             return locMsg;
76         }
77         if (getCause() != null) {
78             return getCause().getLocalizedMessage();
79         }
80         return super.getLocalizedMessage();
81     }
82 }
83
Popular Tags