Skip to main content

wasm4fun_panichandler/
lib.rs

1// Copyright Claudio Mattera 2022.
2//
3// Distributed under the MIT License or the Apache 2.0 License at your option.
4// See the accompanying files License-MIT.txt and License-Apache-2.0.txt, or
5// online at
6// https://opensource.org/licenses/MIT
7// https://opensource.org/licenses/Apache-2.0
8
9//! Panic handler for WASM-4 fantasy console
10
11#![no_std]
12
13#[cfg(target_family = "wasm")]
14use core::arch::wasm32;
15
16#[cfg(target_family = "wasm")]
17use core::panic::PanicInfo;
18
19#[cfg(target_family = "wasm")]
20use wasm4fun_core::trace;
21
22#[cfg(target_family = "wasm")]
23/// Print panic message to the debug console and abort
24#[panic_handler]
25pub fn panic_handler(_panic_info: &PanicInfo<'_>) -> ! {
26    trace("panic error");
27
28    #[cfg(debug_assertions)]
29    if let Some(cause) = _panic_info.payload().downcast_ref::<&str>() {
30        trace(cause);
31    }
32
33    wasm32::unreachable()
34}