Skip to content

Commit 8f34b38

Browse files
committed
Document the error stack
1 parent 5130d33 commit 8f34b38

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

doc/api.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ For installation information, see the [Node-oracledb Installation Instructions][
4444
- 2.1.1 [`errorNum`](#properrerrornum)
4545
- 2.1.2 [`message`](#properrmessage)
4646
- 2.1.3 [`offset`](#properroffset)
47+
- 2.1.4 [`stack`](#properrstack)
4748
3. [Oracledb Class](#oracledbclass)
4849
- 3.1 [Oracledb Constants](#oracledbconstants)
4950
- 3.1.1 [Query `outFormat` Constants](#oracledbconstantsoutformat)
@@ -817,9 +818,23 @@ same is true for invalid operations on read-only or write-only
817818
properties. If an unrecognized property name is used, it will be
818819
ignored.
819820

821+
An example of catching an error is:
822+
823+
```javascript
824+
async function run(connection) {
825+
try {
826+
const sql = `SELECT * FROM DOESNOTEXIST`;
827+
result = await connection.execute(sql);
828+
return result;
829+
} catch (err) {
830+
console.error(err);
831+
}
832+
}
833+
```
834+
820835
### <a name="properror"></a> 2.1 Error Properties
821836

822-
The *Error* object contains `errorNum`, `message` and `offset` properties.
837+
The *Error* object contains `errorNum`, `message`, `offset` and `stack` properties.
823838

824839
#### <a name="properrerrornum"></a> 2.1.1 `errorNum`
825840

@@ -876,6 +891,21 @@ indicating which record could not be processed. See [Handling Data
876891
Errors](#handlingbatcherrors). In node-oracledb 4.2, the maximum `offset` value
877892
was changed from (2^16)-1 to (2^32)-1.
878893

894+
#### <a name="properrstack"></a> 2.1.4 `stack`
895+
896+
```
897+
String stack
898+
```
899+
900+
When using Promises or Async/Await, the *Error* object includes a stack trace,
901+
for example:
902+
903+
```
904+
Error: ORA-00942: table or view does not exist
905+
at async Object.myDoQuery (/Users/cjones/db.js:5:20)
906+
at async run (/Users/cjones/test.js:51:14)}
907+
```
908+
879909
## <a name="oracledbclass"></a> 3. Oracledb Class
880910

881911
The *Oracledb* object is the factory class for *Pool* and *Connection* objects.

0 commit comments

Comments
 (0)