Error Handling

Javascript does not have a global ON ERROR command. It does have a Try / Catch which is similar to the VFP try/catch

catch (err){

In VFP we have DEBUGOUT to send information to the debugger's output window. The same can be done in javascript with the console.log function.
console.log('Some Message');
will send the message to the console.


I have used Safari browser to debug javascript. To get to the debugger in Safari, you first have to turn the Developer menu on ( Preferences - Advanced - Show develop menu in menu bar).

Choosing "Start debugging javascript" from the develop menu will get you to a screen similar to the debug of VFP.

The toolbar at the top has Elements, Resources, Scripts and Console. There are other icons there that I will not be talking of.

Console will have the output of console.log commands. It will also record all errors and warnings. Console is also seen in the bottom pane when you open any other page like Elements or Script.

Elements shows you the html of the current web page. You can select any element which will highlight it in the browser and also give its properties in the right pane. You can also make changes to the web page there.

Resources are the offline persistant information stored. Like cookies, localStorage and Databases. We will be talking of localStorage and Databases later.

Script is the actual javascript debugging. You can set breakpoints, step through code etc,add variable to watch. For more details you can check out

2 Responses to Javascript Vs VFP IV Error Handling and Debugging

  • josip Zohil says:

    “In VFP, if we give a time consuming SQL query, we find that VFP stop responding till the query is complete”.
    Try this experiment:
    1) Create a program with a long running query: Select * from largeData into cursor xxx. Put this program in a VFP project (long.pjx) and compile it in long.exe.
    2) Run your application, for example test.exe.
    3) After that run long.exe.

    The two exes are running in parallel and VFP respond before the query stop. Try this on a slow connection (for example, wi-fi) and a dual core workstation. Long.exe can execute a minute or two (in Windows Task Manager you can see the network transport of 10MB/s. It oscillates). Test.exe responds before Long is complete.

    If you run the two programs Test and Long in the VFP command window, then “…VFP stop responding till the query is complete”.

    I reason in this way: I have two processes (two exes). They don’t interact (have no side- effects). (If they interact, there is another story). The operating system scheduler is managing the two processes. I have no guarantee how the OS execute the two processes. If the processes are simple (small…) and independent I can at least statistically predict theirs execution path ( for example, the first will end in 0.1 second, the next in 0.3 second.

    From a VFP point of view a totally new problem is the coordination of this independent processes. This is a bit more complicated.

    In political language: you need two (or more) not smart processes. On top of them you set a political regime. After that the processes run under the regime plans.

    Normally, I built this “regime” using Erlang, its messaging system and supervisors. In Erlang is easier to reason about concurrency (asynchronous execution). When I solve a problem in Erlang, I try the same in VFP. For me, it is difficult to reason about asynchronous problems in Javascript, because there are too many restrictions, for example, you can’t write to the disk; one of the most important computer resource. It is difficult to parallel work, if a “regime” prohibits you to use resources. It is better to study on a system without prohibitions. Javascript is a wonderful language, but has its limits.

    Best regards Josip Zohil

    • tushar says:

      Actually I am using javascript inside phoneGap ( Phonegap is a wrapper for a web browser and also allows javascript to interact with plugins that are normal libraries. So on the iPhone and Android machines, using javascript and phonegap, I have been able to save/read files, take pictures with the camera, send emails, get notifications. All these would not be possible with just plain javascript, but are enabled because of phonegap.

      Titanium is another development tool that does something similar I think. Also AdobeAir.

      The good part is that there is very little change in code between Android and iPhone if I use phoneGap.

Leave a Reply

Your email address will not be published. Required fields are marked *