Comments (2)
exceptions4c provides a macro e4c_reusing_context
which allows for exception handling inside library functions. This macro reuses an existing exception context, if available when the library function was called. If there is no current exception context, then begins a new one and automatically ends it when finished.
This is an example of the intended usage:
int library_public_function(void * pointer, int number){
// We don't know where this function is going to be called from, so:
// - We cannot use "try", "throw", etc. right here, because the
// exception context COULD be uninitialized at this very moment.
// - We cannot call "e4c_context_begin" either, because the
// exception context COULD be already initialized.
// If we have to make use of the exception handling system, we need
// to "reuse" the existing exception context or "use" a new one.
volatile int status = STATUS_OK;
e4c_reusing_context(status, STATUS_ERROR){
// Now we can safely use "try", "throw", etc.
if(pointer == NULL){
throw(NullPointerException);
}
library_private_function(pointer, number);
}
return(status);
}
I plan to enhance the documentation at the library home page but so far I haven't had the time to do it. In the meantime, you might want to take a look at the source code.
I hope this works for you; please let me know your thoughts about it.
from exceptions4c.
Yes, this works well, and indeed, the e4c.h documentation is well written and clear.
I would also suggest to include a sample with the signal handling (with the warning we catch host signals too, even if it's logic, it's well to warn about it), maybe using the normal e4c map instead of a custom one:
const e4c_signal_mapping *old_mappings = e4c_context_get_signal_mappings();
e4c_context_set_signal_mappings(e4c_default_signal_mappings);
[...]
e4c_context_set_signal_mappings(old_mappings);
Or are there signals we absolutely need to let the host intercept?
from exceptions4c.
Related Issues (9)
- Context has not begun yet? HOT 7
- Mutli-threading fails, though E4C_THREADSAFE is defined HOT 6
- Exception context lost while using dynamic exception-aware libraries
- Is e4c_lite pthread safe? HOT 2
- Uncaught ContextHasNotBegunYet: E4C_TRY HOT 2
- SIGXX should be removed from the calling process's signal mask, when catched signal exceptions ? HOT 1
- Signal is not handled twice with a specific order of headers.
- Signal handling not compatible with exceptions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exceptions4c.