Skip to content

Commit 593cbc9

Browse files
committed
Add a RuntimeException subclass that contains the context of the error
1 parent 8e162fc commit 593cbc9

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package no.ssb.vtl.script.error;
2+
3+
/*
4+
* ========================LICENSE_START=================================
5+
* Java VTL
6+
* %%
7+
* Copyright (C) 2016 - 2017 Hadrien Kohl
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
21+
import org.antlr.v4.runtime.ParserRuleContext;
22+
23+
import static com.google.common.base.Preconditions.checkNotNull;
24+
25+
/**
26+
* A {@link RuntimeException} that contains the context in which it happened.
27+
*/
28+
public class ContextualRuntimeException extends RuntimeException {
29+
30+
private final ParserRuleContext context;
31+
32+
public ContextualRuntimeException(ParserRuleContext context) {
33+
this.context = checkNotNull(context);
34+
}
35+
36+
public ContextualRuntimeException(String message, ParserRuleContext context) {
37+
super(message);
38+
this.context = checkNotNull(context);
39+
}
40+
41+
public ContextualRuntimeException(String message, Throwable cause, ParserRuleContext context) {
42+
super(message, cause);
43+
this.context = checkNotNull(context);
44+
}
45+
46+
public ContextualRuntimeException(Throwable cause, ParserRuleContext context) {
47+
super(cause.getMessage(), cause);
48+
this.context = checkNotNull(context);
49+
}
50+
51+
public ContextualRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, ParserRuleContext context) {
52+
super(message, cause, enableSuppression, writableStackTrace);
53+
this.context = checkNotNull(context);
54+
}
55+
56+
public ParserRuleContext getContext() {
57+
return context;
58+
}
59+
}

0 commit comments

Comments
 (0)