|
| 1 | +/* |
| 2 | + * Copyright (C) 2012-2015 DataStax 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 | +package com.datastax.driver.mapping; |
| 17 | + |
| 18 | +import com.datastax.driver.core.exceptions.DriverException; |
| 19 | +import com.datastax.driver.core.exceptions.DriverInternalError; |
| 20 | + |
| 21 | +import java.util.concurrent.ExecutionException; |
| 22 | + |
| 23 | +/** |
| 24 | + * Copied here from com.datastax.driver.core.DriverThrowables |
| 25 | + * because we don't want this class to be public. |
| 26 | + */ |
| 27 | +class DriverThrowables { |
| 28 | + |
| 29 | + static RuntimeException propagateCause(ExecutionException e) { |
| 30 | + Throwable cause = e.getCause(); |
| 31 | + |
| 32 | + if (cause instanceof Error) |
| 33 | + throw ((Error) cause); |
| 34 | + |
| 35 | + // We could just rethrow e.getCause(). However, the cause of the ExecutionException has likely been |
| 36 | + // created on the I/O thread receiving the response. Which means that the stacktrace associated |
| 37 | + // with said cause will make no mention of the current thread. This is painful for say, finding |
| 38 | + // out which execute() statement actually raised the exception. So instead, we re-create the |
| 39 | + // exception. |
| 40 | + if (cause instanceof DriverException) |
| 41 | + throw ((DriverException) cause).copy(); |
| 42 | + else |
| 43 | + throw new DriverInternalError("Unexpected exception thrown", cause); |
| 44 | + } |
| 45 | +} |
0 commit comments