![]() |
exceptions4c
version 3.0
An exception handling framework for C
|
exceptions4c automatic resource handling header file More...
#include "e4c.h"
Macros | |
Convenience macros for acquiring and disposing resources | |
These macros let you acquire and dispose different kinds of resources according to the dispose pattern. | |
#define | e4c_using_memory(buffer, bytes) |
Introduces a block of code with automatic acquisition and disposal of a memory buffer. More... | |
#define | e4c_using_file(file, path, mode) |
Introduces a block of code with automatic acquisition and disposal of a file stream. More... | |
#define | e4c_using_mutex(mutex) |
Introduces a block of code with automatic acquisition and disposal of a mutex. More... | |
Variables | |
Resource handling exceptions | |
const e4c_exception_type | MemoryAllocationException |
This exception is thrown when malloc returns a null pointer. More... | |
const e4c_exception_type | FileException |
This exception is thrown when a file error occurs. More... | |
const e4c_exception_type | FileOpenException |
This exception is thrown when a file cannot be opened. More... | |
const e4c_exception_type | FileCloseException |
This exception is thrown when a file cannot be closed. More... | |
const e4c_exception_type | MutexException |
This exception is thrown when a mutex error occurs. More... | |
const e4c_exception_type | MutexLockException |
This exception is thrown when a mutex cannot be locked. More... | |
const e4c_exception_type | MutexUnlockException |
This exception is thrown when a mutex cannot be unlocked. More... | |
exceptions4c automatic resource handling header file
This header file needs to be included in order to be able to use any of the automatic resource handling macros:
This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this software. If not, see http://www.gnu.org/licenses/.
#define e4c_using_file | ( | file, | |
path, | |||
mode | |||
) |
Introduces a block of code with automatic acquisition and disposal of a file stream.
file | The file to be acquired, used and then disposed |
path | The path of the file to be opened |
mode | The access mode for the file |
This macro lets you acquire and dispose (open and close) files according to the dispose pattern:
FileOpenException | If fopen returns NULL |
FileCloseException | If fclose does not return zero |
#define e4c_using_memory | ( | buffer, | |
bytes | |||
) |
Introduces a block of code with automatic acquisition and disposal of a memory buffer.
buffer | The buffer to be acquired, used and then disposed |
bytes | The amount of memory to be allocated (in bytes) |
This macro lets you acquire and dispose memory buffers according to the dispose pattern:
MemoryAllocationException | If malloc returns NULL |
#define e4c_using_mutex | ( | mutex) |
Introduces a block of code with automatic acquisition and disposal of a mutex.
mutex | The mutex to be locked, used and then unlocked |
This macro lets you lock and unlock mutexes according to the dispose pattern:
MutexLockException | If pthread_mutex_lock does not return zero |
MutexUnlockException | If pthread_mutex_unlock does not return zero |
const e4c_exception_type FileCloseException |
This exception is thrown when a file cannot be closed.
FileCloseException
is thrown by e4c_using_file
when fclose
does not return zero for whatever reason.
const e4c_exception_type FileException |
This exception is thrown when a file error occurs.
FileException
is the general type of exceptions produced by failed file operations.
error_number
of the exception; it captures the value of errno
at the time the exception was thrown (i. e. right after fopen
or fclose
).const e4c_exception_type FileOpenException |
This exception is thrown when a file cannot be opened.
FileOpenException
is thrown by e4c_using_file
when fopen
returns NULL
for whatever reason.
const e4c_exception_type MemoryAllocationException |
This exception is thrown when malloc returns a null pointer.
MemoryAllocationException
is thrown by e4c_using_memory
when malloc
returns NULL
for whatever reason.
const e4c_exception_type MutexException |
This exception is thrown when a mutex error occurs.
MutexException
is the general type of exceptions produced by failed mutex operations.
const e4c_exception_type MutexLockException |
This exception is thrown when a mutex cannot be locked.
MutexLockException
is thrown by e4c_using_mutex
when fopen
returns NULL
for whatever reason.
const e4c_exception_type MutexUnlockException |
This exception is thrown when a mutex cannot be unlocked.
MutexUnlockException
is thrown by e4c_using_mutex
when fclose
does not return zero for whatever reason.