1 /*
2  * Copyright (C) 2021 The Android Open Source Project
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 androidx.constraintlayout.core.parser;
17 
18 @SuppressWarnings("OverrideThrowableToString")
19 public class CLParsingException extends Exception {
20     private final String mReason;
21     private final int mLineNumber;
22     private final String mElementClass;
23 
CLParsingException(String reason, CLElement element)24     public CLParsingException(String reason, CLElement element) {
25         super(reason);
26         mReason = reason;
27         if (element != null) {
28             mElementClass = element.getStrClass();
29             mLineNumber = element.getLine();
30         } else {
31             mElementClass = "unknown";
32             mLineNumber = 0;
33         }
34     }
35 
36     // @TODO: add description
reason()37     public String reason() {
38         return mReason + " (" + mElementClass + " at line " + mLineNumber + ")";
39     }
40 
41 
42     @Override
toString()43     public String toString() {
44         return "CLParsingException (" + this.hashCode() + ") : " + reason();
45     }
46 }
47