Skip to content

Commit 2c8059a

Browse files
committed
Add "No exception handling?" article
1 parent 957f624 commit 2c8059a

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

content/docs/API/error_types.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ title: Error and Warning Types
55
# Error and Warning Types
66

77
Inspired by Python, we provide the following error and
8-
warning hierarchy. It is for reference only as we decided
9-
not to implement exceptions catching.
8+
warning hierarchy.
9+
10+
<Callout type="info">It is for reference only as we decided
11+
not to implement exceptions catching.<br />
12+
See [No exception handling?](../articles/exception_handling)</Callout>
1013

1114
## Error Hierarchy
1215
To throw an error with a type below, add CTB as prefix and turn it into

content/docs/API/throwing_errors.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ Clear all recorded errors.
148148
```c
149149
void ctb_clear_error(void);
150150
```
151-
<Callout type="warning">This function is not recommended as exception handling is not formally supported</Callout>
151+
<Callout type="warning">This function is not recommended as exception handling is not formally supported.<br />
152+
See [No exception handling?](../articles/exception_handling)</Callout>
152153
153154
### `ctb_dump_traceback` <Badge text="Function" />
154155
Dump the traceback of all recorded errors to stderr and clear errors.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: No exception handling?
3+
---
4+
5+
# No exception handling?
6+
7+
While we support the `Try` part in try/catch, we do not support `Catch` for multiple reasons:
8+
9+
1. To support try and catch, we would need an error stack that could extends to arbitrary depth. However, for the following reasons,
10+
we decided to use a fixed amount of memory for the error stack:
11+
* **Safety**
12+
* Reduce complexity of our implementation
13+
2. C doesn't have exceptions handling, so adding catch would force users to learn a new way to write C, which is bad and makes our library over-complicated for users.
14+
3. You may be tempted to use `ctb_clear_error()` to do exceptions catching. It could be dangerous
15+
if you have some previous errors that you forgot to handle, especially when we are not a language-level framework
16+
to enforce error checking and exiting.

0 commit comments

Comments
 (0)