You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exception is a specialized error class that extends the base Exception class with additional functionality for parser-specific error handling. It automatically includes position information when parsing fails, making it easier to identify and fix syntax errors in schema files.
Exception includes position information to help locate errors in the source code:
34
34
@@ -50,9 +50,9 @@ try {
50
50
}
51
51
```
52
52
53
-
### Common Error Scenarios
53
+
### 2.3. Common Error Scenarios
54
54
55
-
#### Syntax Errors
55
+
#### 2.3.1. Syntax Errors
56
56
57
57
```typescript
58
58
try {
@@ -62,7 +62,7 @@ try {
62
62
}
63
63
```
64
64
65
-
#### Invalid Token Types
65
+
#### 2.3.2. Invalid Token Types
66
66
67
67
```typescript
68
68
try {
@@ -72,7 +72,7 @@ try {
72
72
}
73
73
```
74
74
75
-
#### Unknown References
75
+
#### 2.3.3. Unknown References
76
76
77
77
```typescript
78
78
try {
@@ -82,7 +82,7 @@ try {
82
82
}
83
83
```
84
84
85
-
#### Duplicate Declarations
85
+
#### 2.3.4. Duplicate Declarations
86
86
87
87
```typescript
88
88
try {
@@ -95,7 +95,7 @@ try {
95
95
}
96
96
```
97
97
98
-
## Integration with AST
98
+
## 3. Integration with AST
99
99
100
100
All AST classes throw Exception when parsing fails:
101
101
@@ -118,7 +118,7 @@ try {
118
118
}
119
119
```
120
120
121
-
## Error Recovery
121
+
## 4. Error Recovery
122
122
123
123
While Exception indicates parsing failure, you can implement error recovery strategies:
124
124
@@ -138,7 +138,7 @@ function parseWithFallback(code: string, fallbackCode?: string) {
138
138
}
139
139
```
140
140
141
-
## Language Server Integration
141
+
## 5. Language Server Integration
142
142
143
143
Exception's position information makes it ideal for language server implementations:
144
144
@@ -168,7 +168,7 @@ function validateSchema(code: string) {
168
168
}
169
169
```
170
170
171
-
## Inherited Features
171
+
## 6. Inherited Features
172
172
173
173
Since Exception extends the base Exception class from `@stackpress/lib`, it inherits all the enhanced error handling features:
174
174
@@ -180,9 +180,9 @@ Since Exception extends the base Exception class from `@stackpress/lib`, it inhe
180
180
181
181
For more details on the base Exception functionality, refer to the [@stackpress/lib Exception documentation](https://github.com/stackpress/lib#exception).
182
182
183
-
## Best Practices
183
+
## 7. Best Practices
184
184
185
-
### Always Check Error Type
185
+
### 7.1. Always Check Error Type
186
186
187
187
```typescript
188
188
try {
@@ -198,7 +198,7 @@ try {
198
198
}
199
199
```
200
200
201
-
### Use Position Information
201
+
### 7.2. Use Position Information
202
202
203
203
```typescript
204
204
function highlightError(code:string, error:Exception) {
@@ -222,7 +222,7 @@ function highlightError(code: string, error: Exception) {
222
222
}
223
223
```
224
224
225
-
### Provide Helpful Error Messages
225
+
### 7.3. Provide Helpful Error Messages
226
226
227
227
```typescript
228
228
function parseWithContext(code:string, filename?:string) {
0 commit comments