KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sablecc > sablecc > exception > SemanticException


1 /* This file is part of SableCC ( http://sablecc.org ).
2  *
3  * Copyright 2007 Etienne M. Gagnon <egagnon@j-meg.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.sablecc.sablecc.exception;
19
20 import org.sablecc.sablecc.syntax3.node.Token;
21
22 public class SemanticException
23         extends Exception JavaDoc {
24
25     private static final long serialVersionUID = 155544165804671040L;
26
27     private Token token;
28
29     public SemanticException(
30             String JavaDoc message,
31             Token token) {
32
33         super("[" + token.getLine() + "," + token.getPos() + "] " + message);
34
35         if (message == null) {
36             throw new InternalException("message may not be null");
37         }
38
39         if (token == null) {
40             throw new InternalException("token may not be null");
41         }
42
43         this.token = token;
44     }
45
46     public SemanticException(
47             String JavaDoc message,
48             Token token,
49             Throwable JavaDoc cause) {
50
51         super("[" + token.getLine() + "," + token.getPos() + "] " + message,
52                 cause);
53
54         if (message == null) {
55             throw new InternalException("message may not be null");
56         }
57
58         if (token == null) {
59             throw new InternalException("token may not be null");
60         }
61
62         if (cause == null) {
63             throw new InternalException("cause may not be null");
64         }
65
66         this.token = token;
67     }
68
69     public Token getToken() {
70
71         return this.token;
72     }
73 }
74
Popular Tags