Skip to content

Commit

Permalink
Update panic
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Oct 8, 2024
1 parent fe3f5b1 commit 228cf49
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions examples/panics/panics.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Panics

Ballerina distinguishes normal errors from abnormal errors. Normal errors are handled by returning error values. Abnormal errors are handled using the panic statement. Abnormal errors should typically result in immediate program termination.

E.g., A programming bug or out of memory. A panic has an associated error value.
Ballerina distinguishes normal errors from abnormal errors. Normal errors are handled by returning error values. This signals to the caller that they must handle the error. In contrast, abnormal errors such as division by 0 and out-of-memory are typically unrecoverable errors and we need to terminate the execution of the program. This is achieved by a panic statement, which expects an expression that results in an error value such as the error constructor. At runtime evaluating a panic statement first create the error value by evaluating the expression and then start stack unwinding. In this process, if it comes across a trap expression it stops further unwinding and as a result of that trap expression, you will get the error created at the panic statement.

::: code panics.bal :::

::: out panics.out :::
::: out panics.out :::

0 comments on commit 228cf49

Please sign in to comment.