[lucy-user] About error handling in Lucy C library

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[lucy-user] About error handling in Lucy C library

serkanmulayim@gmail.com
Hi guys,

According to the documentation, I see there is an exception/error handling mechanism built in the C library. For example in https://lucy.apache.org/docs/c/Lucy/Index/Indexer.html, "If a write lock cannot be secured, new() will throw an exception". Or in the Indexer.c the code line "THROW(ERR, "No Schema supplied, and can't find one in the index");"

Is there any documentation on how we can use these exceptions for building safer applications? Is there a documentation for all "classes"  which throws exceptions with the corresponding functions? Is there any code examples on how they are used?

Is there any documentation on the functions which return a status (e.g 0 for success -1 for lock error etc...) of the method as well?

Thanks in advance,
Serkan

Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] About error handling in Lucy C library

Tilghman Lesher
On Wed, Feb 1, 2017 at 2:53 PM, Serkan Mulayim <[hidden email]> wrote:
> According to the documentation, I see there is an exception/error handling mechanism built in the C library. For example in https://lucy.apache.org/docs/c/Lucy/Index/Indexer.html, "If a write lock cannot be secured, new() will throw an exception". Or in the Indexer.c the code line "THROW(ERR, "No Schema supplied, and can't find one in the index");"
>
> Is there any documentation on how we can use these exceptions for building safer applications? Is there a documentation for all "classes"  which throws exceptions with the corresponding functions? Is there any code examples on how they are used?

The documentation for Exceptions appears to be here:
https://lucy.apache.org/docs/c/Clownfish/Err.html

Note the trap() API call.

> Is there any documentation on the functions which return a status (e.g 0 for success -1 for lock error etc...) of the method as well?

I believe the library is designed to be embedded in a language which
does exception handling, so it does not appear so.

--
Tilghman
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] About error handling in Lucy C library

Nick Wellnhofer
In reply to this post by serkanmulayim@gmail.com
On 01/02/2017 21:53, Serkan Mulayim wrote:
> Is there any documentation on how we can use these exceptions for building safer applications? Is there a documentation for all "classes"  which throws exceptions with the corresponding functions? Is there any code examples on how they are used?

As Tilghman already pointed out, you can catch exceptions from C with the
Err_trap function. You can find usage examples in the Clownfish test suite and
in the FastUpdates cookbook entry:

     https://lucy.apache.org/docs/c/Lucy/Docs/Cookbook/FastUpdates.html

Err_trap calls a `void (*f)(void *ctx)` function pointer with a user-supplied
context and returns the exception as Err object, or NULL on success.

Exceptions are also thrown on out-of-memory errors, so almost any method could
throw.

> Is there any documentation on the functions which return a status (e.g 0 for success -1 for lock error etc...) of the method as well?

There are very few methods in the public API that return a status, mostly in
the locking code:

     https://lucy.apache.org/docs/c/Lucy/Store/Lock.html

In case of an error, you can get the Err object with Err_get_error. This
behavior is explained in the documentation.

Nick