The error is related to applications

A replacement value greater than 1 indicates that a platform has occurred. The value of errno returned by the system is simply returned by the function; For example, if a Berkeley DB function cannot determine memory, the return value of one of our functions is ENOMEM.

If errors occur while designing a part interface, you can choose from several styles to return the errors. If the function is indeed synchronous, you can either return a signal value indicating that an error will occur and which is easy to distinguish from the original result (often null in javascript), or you can also create an exception to which you can return an object with a property indicating that you see the success or failure of this operation.

If you have an asynchronous operation through an interface, most Promise One will reject a Promise with a distinct Error object as the reject reason in the marketplace to indicate an error . This is the heart of promise design theory. Success with the optional resolution of understanding, rejection of failure with reason.

Return database
    return value;
    return new Error('Kkey(' + factor + ") available: not inside + error);

Resolves the underlying promise returned with a value for money or Error object. This is usually written encoding without promises, since the caller has to check the change of the allowed value to see if there is an error or not, which is not a simple and straight forward way to use promises. So, to your question, you probably usually do:

return do dbstore.getItem(key).catch(function(err)
    throw new Error('Available (' + key + "): this is not " + err);

There are alternate characters in this function, usually it’s just bad code.

  1. .then(function(value) return value;) becomes completely redundant and unnecessary. It doesn’t add value. value is already a managed promise value. It does not need to be declared again.

  2. The target sometimes returns a promise and sometimes throws a synchronous exception.
    This is another pain to use. If you look at the main if (!key){ statement, it will get an Error object if the key type is not provided with an argument. In general, when using this function, you must catch synchronous exceptions, pass .then() and .Handlers catch() And check the permission type it helps you to be an error. Wearing this feature is a nightmare. This is bad code.

In order to use a function of any type, the user will probably have to do the following:

let retVal = someObj.get(aKey);
if (type retVal ===
 error) // finally got a synchronous error
 it is better
    retVal.then(val =>
        if (value type === error)
            I got // async error
            Got // concrete success value here
    ).catch(error =>
        // received an asynchronous error

get(key,=handle null)

 => // clicked here successful value
).catch(error =>
    I have an error here

Can you return an error Javascript?

If the target is in sync, you can either return a Sentinel value that indicates a big error and can be easily distinguished far from the actual result (often null due to javascript), or you can throw a new big exception, or you can return a distinctive object that has a property indicating the success or failure of the operation.

Compare the ease of calling here with the game above.

  1. It always returns a promise. If key is not specified, continue with Promise Rejected.
  2. All errors are directly due to the rejected value proposition.
  3. The statistic that dissolves desire is still quite successful.
  4. No .then() handler which might not do anything useful.

Beyond our own history of ndbm dbm and hsearch
Interfaces, Berkeley DB does not use global variable
errno so you can return error values. v
Duplicate values ​​for all Berkeley DB options grouped
which is shortly after three categories:

How do I return an error?

Change the function to return two values: range and error.
Import the error package from the Go standard library so you can use its errors.
Add excellentth new if statement to check if it finds an invalid request (an empty string fragment where the name should be), combined with an error if the request is not valid.

Although possible errors are repeated, they are signaled by each
Personal function help page, there are some bugs
Performances worthy of public mention:


There are usually two special return values ​​that are usually similar.
value and which can be returned in similar situations, and
so it could be confusing: DB_NOTFOUND and

return indicates that the particular key/data pair requested was not
exist in the database or have a specific start or end of file
recently got under the cursor.

return indicates which requested key/data pair is a logical
Exists but has never been explicitly created by the application
(Recno and Queue accessors must be forced
key/data pairs in certain circumstances; see DB->open() for more information
information) or that the requested key/data pair has been deleted
and recreated for no reason. Also, the queue starts with a lookup method
returns DB_KEYEMPTY intended for records that are almost partially created
a transaction that was later reversed and never considered
Newly created.


When should you return an error?

Always throw out bugs and only package them if buyers want to deal with them. Reimburse only correctable errors, discard the rest. Return expected errors, discard (or eliminate) the rest. Returns any error, implies a throw.