Skip to content

Commit f6bc2d1

Browse files
authored
Merge pull request #436 from gyorokpeter/c_error_reporting
add more info about error catching and rethrowing
2 parents 5251c17 + f6d65f7 commit f6bc2d1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/interfaces/c-client-for-q.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ It is similar to `krr(S)`, but it appends a system error message to the user-pro
664664

665665
1. To catch an error code from the results of a call to `r=k(h, …)`, check the return value and type.
666666
If result is `NULL`, then a network error has occurred.
667-
If it has type -128, then `r->s` will point to the error string. Note that K object with type -128 acts as a marker only and other uses are not supported(i.e. passing it to other C API or kdb+ functions).
667+
If it has type -128, then `r->s` will point to the error string. Note that K object with type -128 acts as a marker only and other uses are not supported (i.e. passing it to other C API or kdb+ functions).
668668

669669
```c
670670
K r=k(handle, "f", arg1, arg2, (K)0);
@@ -675,6 +675,26 @@ if(r && -128==r->t)
675675
Under some network-error scenarios, `errno` can be used to obtain the details of the error,
676676
e.g. `perror(“network”);`
677677
678+
Some functions such as [`dot`](capiref.md#dot-apply) return `NULL` on error. These require calling [`ee`](capiref.md#ee-error-string) to retrieve the error.
679+
680+
The error object returned from `k` or `ee` can be rethrown by returning it. No need to call `krr`, `r1` or `r0`.
681+
682+
```c
683+
K r=k(0, "1+`a", (K)0);
684+
if(r && -128==r->t)
685+
return r;
686+
```
687+
688+
On the other hand, to swallow the error, `r0` must be called on it to avoid leaking memory.
689+
690+
```c
691+
K r=k(0, "1+`a", (K)0);
692+
if(r && -128==r->t) {
693+
printf("error string: %s\n", r->s);
694+
r0(r);
695+
return kj(0);
696+
}
697+
```
678698

679699
## Return values
680700

0 commit comments

Comments
 (0)