KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > inject > ProvisionException


1 /**
2  * Copyright (C) 2006 Google Inc.
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
17 package com.google.inject;
18
19 import com.google.inject.util.StackTraceElements;
20 import java.lang.reflect.Member JavaDoc;
21
22 /**
23  * Used to rethrow exceptions that occur while providing instances, to add
24  * additional contextual details.
25  */

26 class ProvisionException extends RuntimeException JavaDoc {
27   public ProvisionException(ExternalContext<?> externalContext,
28       Throwable JavaDoc cause) {
29     super(createMessage(externalContext), cause);
30   }
31
32   private static String JavaDoc createMessage(ExternalContext<?> externalContext) {
33     Key<?> key = externalContext.getKey();
34     Member JavaDoc member = externalContext.getMember();
35     return String.format(ErrorMessages.EXCEPTION_WHILE_CREATING,
36         ErrorMessages.convert(key),
37         StackTraceElements.forMember(member));
38   }
39 }
40
Popular Tags