Skip to content

Commit

Permalink
A note about misleading stack trace in finally blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
aajanki committed Jan 2, 2025
1 parent 3a88f46 commit 244f145
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions language_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ try {
}
```

If an exception gets thrown inside a try block, the stack trace in Workflows logs will misleadingly show the exception originating from inside the finally block. This happens because the implementation of the finally block catches the original exception and later throws an identical exception. The original source location of the exception is lost.

⚠️ At the moment, break and continue are not supported in a try or a catch block if there is a related finally block.

## Retrying on errors
Expand Down Expand Up @@ -676,16 +678,16 @@ main:
return: Error!
```

Finally and catch blocks are run after possible retry attempts. The following sample retries `http.get()` if it throws an exception and executes `log('Error!')` and `closeConnection()` after retry attempts.
Finally and catch blocks are run after possible retry attempts. The following sample retries `http.get()` if it throws an exception and executes `sys.log('Error!')` and `closeConnection()` after retry attempts.

```javascript
import { http, retry_policy } from 'ts2workflows/types/workflowslib'
import { http, retry_policy, sys } from 'ts2workflows/types/workflowslib'
function main() {
try {
http.get('https://visit.dreamland.test/')
} catch (err) {
log('Error!')
sys.log('Error!')
} finally {
closeConnection()
}
Expand Down Expand Up @@ -812,7 +814,7 @@ function retry_policy(
): void
```

The `retry_policy` function can called right after a `try`-`catch` block to specify a retry policy. See the section on retrying.
The `retry_policy` function can called right after a `try`-`catch` block to specify a retry policy. See the section on [retrying errors](#retrying-on-errors).

## Source code comments

Expand Down

0 comments on commit 244f145

Please sign in to comment.