Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use null-check for allocators instead of try/catch #88

Closed
wants to merge 1 commit into from

Conversation

osialr
Copy link
Contributor

@osialr osialr commented Mar 11, 2016

I wanted to compile the library with -fno-exceptions so this makes use of new (std::nothrow) in the allocators and marks the generated allocators as @NoException.

Also, it prevents JavaCPP_exception from being emitted when no exceptions are used in the code

@saudet
Copy link
Member

saudet commented Mar 12, 2016

C++ constructors are allowed to throw exceptions, so as per #84, could you make it so that only allocators for structs defined in a C header files and included via cinclude are annotated with @NoException?

Also, there are cases when handleExceptions doesn't get flagged, but where JavaCPP_exception gets used... I'll have to check that.

@osialr
Copy link
Contributor Author

osialr commented Mar 13, 2016

Oh right, allocate could call C++ ctors which could throw. The Parser would need to compare against cinclude

I'll close this one out and combine something with a variant of #86

@osialr osialr closed this Mar 13, 2016
@saudet
Copy link
Member

saudet commented Mar 13, 2016

BUT it's really not a good idea to have C++ destructors throw exceptions, so it's not something that we're likely to see... So I don't know, should we really remove throws Exception from Pointer.close() altogether? Maybe it makes sense in the sense that even if something were to get thrown from it, C++ doesn't have checked exceptions, so removing it from close() would look OK from the C++ side of things. What do you think?

@osialr
Copy link
Contributor Author

osialr commented Mar 14, 2016

It's true that C++ destructors shouldn't throw and the program may call std::terminate if it throws.

To play devil's advocate, removing throws Exception would cause a compile error for end-users that created a subclass with close() throws Exception. In the interest of backwards compatibility, it makes sense to leave it as-is until a 2.0.

@saudet
Copy link
Member

saudet commented Mar 14, 2016

I don't think any users created such subclasses. It's too new of a feature. ;) IMO, it wouldn't be a large API change, so for a 1.1->1.2 jump, I wouldn't have any issues with that. I just want to make sure that not having a checked exception is the best thing to do, regardless of versioning...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants