Getting rid of this error: Error: Using exceptions for control flow, don't mind me. This isn't actually an error!

Context: learning wgpu.

Question: wtf is this, and how do I get rid of it? I am not a fan of having dev console cluttered with "not important" red-colored exceptions.

Full error:

Uncaught (in promise) Error: Using exceptions for control flow, don't mind me. This isn't actually an error!
    at imports.wbg.__wbindgen_throw (client_w.js:638:15)
    at wasm_bindgen::throw_str::h62f5642fc6d5306c (client_w_bg.wasm:0x2263c)
    at winit::platform_impl::platform::backend::throw::ha800ba428cc0c27f (client_w_bg.wasm:0x225f0)
    at winit::platform_impl::platform::event_loop::EventLoop<T>::run::h62ffc10679c19025 (client_w_bg.wasm:0x1ec53)
    at winit::event_loop::EventLoop<T>::run::h63f64260aa90cdb4 (client_w_bg.wasm:0x1f1e0)
    at game_client::run::h8aba375cf0be9784 (client_w_bg.wasm:0x17eff)
    at client_w::main::hfc8f233646a5b522 (client_w_bg.wasm:0x228a8)
    at finalizeInit (client_w.js:691:10)
    at init (client_w.js:723:12)
imports.wbg.__wbindgen_throw	@	client_w.js:638
$wasm_bindgen::throw_str::h62f5642fc6d5306c	@	client_w_bg.wasm:0x2263c
$winit::platform_impl::platform::backend::throw::ha800ba428cc0c27f	@	client_w_bg.wasm:0x225f0
$winit::platform_impl::platform::event_loop::EventLoop<T>::run::h62ffc10679c19025	@	client_w_bg.wasm:0x1ec53
$winit::event_loop::EventLoop<T>::run::h63f64260aa90cdb4	@	client_w_bg.wasm:0x1f1e0
$game_client::run::h8aba375cf0be9784	@	client_w_bg.wasm:0x17eff
$client_w::main::hfc8f233646a5b522	@	client_w_bg.wasm:0x228a8
finalizeInit	@	client_w.js:691
init	@	client_w.js:723
Promise.then (async)		
(anonymous)
1 Like

Well it comes from here: winit/mod.rs at 2486f0f1a1d00ac9e5936a5222b2cfe90ceeca02 · rust-windowing/winit · GitHub

The code seems like it is spawning your event handler into an asnyc JS backend, then it has to not return from run to keep the signature consistent with native platforms, hence the throw.

It seems like there should be a higher level handler catching and discarding this error that's missing: but I can't see where this would be added in the template, nor should wasm-bindgen know about the error to ignore it. Very strange.

You should be able to suppress this on the JS side by catching the rejection from init and ignoring it if the message matches:

init().catch((error) => {
  if (!error.message.startsWith("Using exceptions for control flow,")) {
    throw error;
  }
});

though you shouldn't have to... Perhaps double check if you get this in one of the examples?

I typed up the example from learn-wgpu/lib.rs at master · sotrh/learn-wgpu · GitHub ; maybe I added a typo somewhere.

Will try the catch-in-JS technique. Thanks!

@simonbuchan After reading that code, I changed the run to a spawn from my side -- I'm not seeing bad side effects so far, is there any reason this would not work ?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.