Catch and Handle CasperError

casperjs

Solution

I use something currently like this:

casper.on('error', function(msg,backtrace) {
  this.capture('./out/error.png');
  throw new ErrorFunc("fatal","error","filename",backtrace,msg);
});

and then I have a custom function `ErrorFunc` to process array of any warnings or a fatal error.

If you have an unsuccessful click it should throw the `casper.on('error')`. So you can put custom code there for how you would like to handle the error.

Here's the documentation for Casper events.

Problem

Using CasperJS how do I catch and handle CasperError? The default appears to continue execution of the program (which does nothing but propagates the error). These errors are logged to the console/stdout but I don't seem to see a way (from the docs) to catch and handle these errors. Example: ``` this.fillSelectors(selector, data); ``` May produce: CasperError: Errors encountered while filling form: form not found I know I can check to make sure everything exists before calling, but is there a way to catch after the fact? (this applies to many other operations like `casper.click` as well)

Original source