Line | Hits | Source |
---|---|---|
1 | /* | |
2 | Chrysalis Web Framework [http://chrysalis.sourceforge.net] | |
3 | Copyright (c) 2002, 2003, 2004, Paul Strack | |
4 | ||
5 | All rights reserved. | |
6 | ||
7 | Redistribution and use in source and binary forms, with or without | |
8 | modification, are permitted provided that the following conditions are met: | |
9 | ||
10 | 1. Redistributions of source code must retain the above copyright notice, this | |
11 | list of conditions and the following disclaimer. | |
12 | ||
13 | 2. Redistributions in binary form must reproduce the above copyright notice, | |
14 | this list of conditions and the following disclaimer in the documentation | |
15 | and/or other materials provided with the distribution. | |
16 | ||
17 | 3. Neither the name of the copyright holder nor the names of its contributors | |
18 | may be used to endorse or promote products derived from this software without | |
19 | specific prior written permission. | |
20 | ||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | package org.chwf.resources; | |
34 | ||
35 | /** | |
36 | * Exception for resource-related errors. Wraps the root cause. This | |
37 | * exception also supports creating arbitrarily long chains of resource | |
38 | * exceptions. | |
39 | * | |
40 | * @author Paul Strack | |
41 | */ | |
42 | public class ResourceException extends Exception { | |
43 | ||
44 | /** Root cause. */ | |
45 | private final Throwable cause; | |
46 | ||
47 | /** Chained exception. */ | |
48 | private ResourceException chainedException; | |
49 | ||
50 | /** Message key */ | |
51 | static final String MESSAGE_RESOURCE_RELEASE_FAILURE = | |
52 | "RESOURCE_RELEASE_FAILURE"; | |
53 | ||
54 | /** | |
55 | * Constructor. | |
56 | * | |
57 | * @param message A message. | |
58 | */ | |
59 | public ResourceException(String message) { | |
60 | 2 | this(message, null); |
61 | 2 | } |
62 | ||
63 | /** | |
64 | * Constructor. | |
65 | * | |
66 | * @param cause The root cause. | |
67 | */ | |
68 | public ResourceException(Throwable cause) { | |
69 | 3 | this(cause.toString(), cause); |
70 | 3 | } |
71 | ||
72 | /** | |
73 | * Constructor. | |
74 | * | |
75 | * @param message A message. | |
76 | * @param cause The root cause. | |
77 | */ | |
78 | public ResourceException(String message, Throwable cause) { | |
79 | 5 | super(message); |
80 | 5 | this.cause = cause; |
81 | 5 | } |
82 | ||
83 | /** | |
84 | * Root cause. | |
85 | * | |
86 | * @return Root cause. | |
87 | */ | |
88 | public Throwable getCause() { | |
89 | 2 | return cause; |
90 | } | |
91 | ||
92 | /** | |
93 | * Method for chaining multiple resource exceptions. | |
94 | * | |
95 | * @param ex The resource exception to chain. | |
96 | */ | |
97 | public void setNextException(ResourceException ex) { | |
98 | 4 | if (this.chainedException == null) { |
99 | 4 | this.chainedException = ex; |
100 | } else { | |
101 | 0 | this.chainedException.setNextException(ex); |
102 | } | |
103 | 4 | } |
104 | ||
105 | /** | |
106 | * The next chained exception, or null if there is none. | |
107 | * | |
108 | * @return The next chained exception, or null if there is none. | |
109 | */ | |
110 | public ResourceException getNextException() { | |
111 | 1 | return this.chainedException; |
112 | } | |
113 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |