try catch file not found

I have made a function in a javascript file to dynamically load images based on variables.
I need for my game to be ok with sometimes trying to load a file that isn't there.
I want it to not load any image, and carry on with the game.

As far as I know there is no way to safely check if a file exists before trying to load it.
I have encased the $gameScreen.showPicture in a try block, with a catch(err) {return;} following it,
but it still stops the program the same as if the try/catch was not there.
So what is the point of a try catch? It doesn't work.
It might be that you simply made a mistake in your code - if you present it here, someone can check it.
Moved to: Learning Javascript
If only checking locally on the desktop you can use Node existsSync. It will return true or false. As for browser support when doing your XHR request check the status for a 404 and return true or false depending on the status. In browser, it will always log a warning saying the file was not found but it won't interrupt gameplay.
As Andar said though, if you show some code maybe we can help you further.
I do not know if this can help, but the line you're looking for is here during the process
at bitmap._image.onerror = Bitmap.prototype._onError.bind(bitmap);

Maybe put a conditional that verified bitmap.url
And set null filename ?
because you can do
$gameScreen.showPicture(pictureId, null, .....
and this will not give error.

Code:
/**
 * Loads a image file and returns a new bitmap object.
 *
 * @static
 * @method load
 * @param {String} url The image url of the texture
 * @return Bitmap
 */
Bitmap.load = function(url) {
    var bitmap = new Bitmap();
    bitmap._image = new Image();
    bitmap._url = url;
    bitmap._isLoading = true;

    if(!Decrypter.checkImgIgnore(url) && Decrypter.hasEncryptedImages) {
        Decrypter.decryptImg(url, bitmap);
    } else {
        bitmap._image.src = url;
        bitmap._image.onload = Bitmap.prototype._onLoad.bind(bitmap);
        bitmap._image.onerror = Bitmap.prototype._onError.bind(bitmap);
    }

    return bitmap;
};

Original thread: https://forums.rpgmakerweb.com/threads/try-catch-file-not-found.78450/