Preventing a missing or faulty plugin loaded inside of wp-settings from halting a script

foreach ( wp_get_active_and_valid_plugins() as $  plugin ) {     echo $  plugin;     wp_register_plugin_realpath( $  plugin );     include_once $  plugin;      /**      * Fires once a single activated plugin has loaded.      *      * @since 5.1.0      *      * @param string $  plugin Full path to the plugin's main file.      */     do_action( 'plugin_loaded', $  plugin );     echo 'end'; } 

So I have a script that loads wp-settings and the script halts at: /var/www/public/wp-content/plugins/w3-total-cache/w3-total-cache.php. I am thinking that do_action(‘plugin_loaded’, $ plugin); throws an exception and stops the script from running, how do you prevent an exception like that from halting a script? I tried to put a try catch, but it doesn’t work.