Skip to content

Conversation

@bettio
Copy link
Collaborator

@bettio bettio commented Nov 7, 2025

See also #1951

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@bettio bettio force-pushed the error-handling-rework branch 4 times, most recently from c8e8d05 to e8830d4 Compare November 11, 2025 20:12
@bettio
Copy link
Collaborator Author

bettio commented Feb 4, 2026

I will back to this PR after this discussion: https://erlangforums.com/t/question-about-how-vm-deals-with-exceptions/5410
I need to clarify how cleanup should be done.

@bettio bettio force-pushed the error-handling-rework branch 4 times, most recently from 0380b66 to 2dc5720 Compare February 11, 2026 09:51
RAISE()/RAISE_ERROR() is more maintainable than directly writing to registers.

Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio bettio force-pushed the error-handling-rework branch from 2dc5720 to af4ebb5 Compare February 11, 2026 10:40
Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio bettio force-pushed the error-handling-rework branch from 26d571e to b98105e Compare February 11, 2026 17:36

#ifdef IMPL_EXECUTE_LOOP
RAISE_ERROR(FUNCTION_CLAUSE_ATOM);
RAISE_ERROR_MFA(FUNCTION_CLAUSE_ATOM, module_atom, function_name_atom, arity);

Check failure

Code scanning / CodeQL

Passing a non-term to a function expecting a term Error

Passing a non-term to a function expecting a term, without an explicit cast

#ifdef IMPL_EXECUTE_LOOP
RAISE_ERROR(FUNCTION_CLAUSE_ATOM);
RAISE_ERROR_MFA(FUNCTION_CLAUSE_ATOM, module_atom, function_name_atom, arity);

Check failure

Code scanning / CodeQL

Passing a non-term to a function expecting a term Error

Passing a non-term to a function expecting a term, without an explicit cast
@bettio bettio added this to the v0.7.0 milestone Feb 12, 2026
This change follows what the BEAM is already doing: exception
information is temporarily stored in the process structure rather than
returning it using x[0..2] registers.

Following fields are added to Context for this purpose: exception_class,
exception_reason, exception_stacktrace.

Their lifespan is just the time required to build a raw stacktrace,
after that, they can be safely discarded.

Future AtomVM version might move those new fields to the
emulator/execution environment rather having them for each process.

Since they are super-short lived, GC ignores them.

This approach has been confirmed by BEAM devs.

Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio bettio force-pushed the error-handling-rework branch from b98105e to 8ddd802 Compare February 12, 2026 08:46
raise/3 allows to (re-)raise an exception while keeping the already
existing stacktrace.
This change make this work, by supporting the 3rd raise parameter, and
changing `stacktrace_build` and `stacktrace_create_raw` accordingly`.

Fixes atomvm#1951
Closes atomvm#1804

Signed-off-by: Davide Bettio <davide@uninstall.it>
Make sure that is a 6-arity tuple, before taking any element from it.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio bettio force-pushed the error-handling-rework branch from 8ddd802 to c0cec4c Compare February 12, 2026 11:15
Signed-off-by: Davide Bettio <davide@uninstall.it>
Signed-off-by: Davide Bettio <davide@uninstall.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant