| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=MAX_LOCATION_LEN), | public | :: | call_stack(MAX_STACK_DEPTH) |
Call locations Cause chain support (Rust-style “caused by”) |
|||
| integer(kind=default_int), | public | :: | cause_codes(MAX_CAUSE_DEPTH) |
Error codes of wrapped causes |
|||
| integer(kind=default_int), | public | :: | cause_depth | = | 0 |
Number of wrapped causes |
|
| character(len=MAX_CAUSE_MSG_LEN), | public | :: | cause_messages(MAX_CAUSE_DEPTH) |
Messages of wrapped causes |
|||
| integer(kind=default_int), | public | :: | code | = | SUCCESS |
Error code (0 = no error) |
|
| character(len=:), | public, | allocatable | :: | message |
Error message Stack trace support |
||
| integer(kind=default_int), | public | :: | stack_depth | = | 0 |
Current stack depth |
Add a call location to the stack trace Typically called when propagating errors upward
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(inout) | :: | self | |||
| character(len=*), | intent(in) | :: | location |
Clear the error state, stack trace, and cause chain
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(inout) | :: | self |
Print the error trace and stop the program Use for unrecoverable errors
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self | |||
| integer(kind=default_int), | intent(in), | optional | :: | unit |
Get the error code
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self |
Get complete error message with cause chain and stack trace Returns a dynamically-sized multi-line string
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self |
Get the error message (without stack trace)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self |
Check if an error is set
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self |
Check if the error matches a specific error code
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self | |||
| integer(kind=default_int), | intent(in) | :: | code |
Print error with cause chain and stack trace to specified unit If unit not specified, prints to stdout
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self | |||
| integer(kind=default_int), | intent(in), | optional | :: | unit |
Wrap the current error with a higher-level context Pushes the current error into the cause chain and sets a new top-level code and message (Rust-style “caused by”)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(inout) | :: | self | |||
| integer(kind=default_int), | intent(in) | :: | code | |||
| character(len=*), | intent(in) | :: | message |
type :: error_t integer(default_int) :: code = SUCCESS !! Error code (0 = no error) character(len=:), allocatable :: message !! Error message !! Stack trace support integer(default_int) :: stack_depth = 0 !! Current stack depth character(len=MAX_LOCATION_LEN) :: call_stack(MAX_STACK_DEPTH) !! Call locations !! Cause chain support (Rust-style "caused by") integer(default_int) :: cause_depth = 0 !! Number of wrapped causes integer(default_int) :: cause_codes(MAX_CAUSE_DEPTH) !! Error codes of wrapped causes character(len=MAX_CAUSE_MSG_LEN) :: cause_messages(MAX_CAUSE_DEPTH) !! Messages of wrapped causes contains procedure :: has_error => error_has_error procedure :: set => error_set procedure :: clear => error_clear procedure :: get_code => error_get_code procedure :: get_message => error_get_message procedure :: is => error_is procedure :: wrap => error_wrap procedure :: add_context => error_add_context procedure :: get_full_trace => error_get_full_trace procedure :: print_trace => error_print_trace procedure :: fatal => error_fatal end type error_t