Move more set_panic_handler()
logic into Rust
#11704
Merged
set_panic_handler()
logic into Rust
#11704