https://github.com/jwerle/throw.h
Create and throw errors easily
https://github.com/jwerle/throw.h
Last synced: over 1 year ago
JSON representation
Create and throw errors easily
- Host: GitHub
- URL: https://github.com/jwerle/throw.h
- Owner: jwerle
- License: mit
- Created: 2013-10-14T14:19:49.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-25T15:45:56.000Z (over 12 years ago)
- Last Synced: 2025-01-17T01:14:58.118Z (over 1 year ago)
- Language: C
- Size: 129 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
throw.h
=======
Create and throw errors easily
## install
With [clib](https://github.com/clibs/clib)
```sh
$ clib install jwerle/throw.h
```
## usage
```c
#include "throw.h"
int
main (void) {
error_t eperm = error_new(EPERM, "EPERM");
error_t enoent = error_new(ENOENT, "ENOENT");
error_t esrch = error_new(ESRCH, "ESRCH");
error_t eintr = error_new(EINTR, "EINTR");
throw(&eperm, "Operation not permitted");
throw(&enoent, "No such file or directory");
throw(&esrch, "No such process");
throw(&eintr, "Interrupted system call");
return 0;
}
```
You can also set the stream where errors are written to by defining the
`THROW_FD` file descriptor.
```c
THROW_FD = stderr; // or some other `FILE *` pointer
```
## license
MIT