View Javadoc
1   /*
2    * Copyright 2004 Diogo Quintela (dquintela@users.sourceforge.net)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.whatsnew.exceptions;
17  
18  import net.sf.whatsnew.lang.Messages;
19  
20  
21  /***
22   * <p>
23   * Application Level exception
24   * </p>
25   *
26   * @author <a href="mailto:dquintela@users.sourceforge.net">Diogo Quintela</a>
27   * @version $Id: AppException.java,v 1.1 2004/05/13 01:22:39 dquintela Exp $
28   */
29  public class AppException
30  extends Exception {
31      /***
32       * Creates a new AppException object.
33       */
34      public AppException() {
35          super();
36      }
37  
38      /***
39       * Creates a new AppException object, with message identified with
40       * <code>key</code>
41       *
42       * @param key the detail message.
43       *
44       * @see net.sf.whatsnew.lang.Messages
45       */
46      public AppException(String key) {
47          this(key, false);
48      }
49  
50      /***
51       * Creates a new AppException object.
52       *
53       * @param value The value for the key or the message
54       * @param useBundle true, <code>value</code> will be used as message
55       *        identifier, false, <code>value</code> will be message associated
56       *        with exception
57       *
58       * @see net.sf.whatsnew.lang.Messages
59       */
60      public AppException(
61          String value,
62          boolean useBundle) {
63          super(useBundle ? Messages.getString(value) : value);
64      }
65  
66      /***
67       * Prints exception
68       *
69       * @param debug Debug on or off
70       */
71      public void print(boolean debug) {
72          if (debug) {
73              printStackTrace();
74          } else {
75              synchronized (System.err) {
76                  System.err.print(this);
77              }
78          }
79      }
80  }
81  // EOF