Question: So I have a python module that receives data and uploads it to a database.
I have a table health check that checks if the table is present, if number of columns is what it should be, also the types and names of columns.

So I have a bit of code like that:

```
def log_msg(message):
        try:
            insert(message)
        except sqlite3.OperationalError:
            table_health()
            log_msg(message)

```

`table_health()` drops the table if there's anything wrong with it and creates a new one.

I want the module to be able to fix the database, since data will be reported continuously. That's why I don't want to raise an exception, I've decided to handle it like that. 

I also don't want to check health before executing the query, because this health check is performed at module import, so table should be ok prior to execution. The only problem arises if the table is dropped/changed during runtime. But most of the time table should be fine, so checking before every query seems like a waste - hence check on error.

Only solution to a possible infinite recursion I can see is to make sure log\_msg is executed after an exception only once. By replacing it with `insert(message)`
Since if the table is going to be fixed, it's after one execution. Otherwise there's something wrong

Any suggestions on how to handle this?

Answer: 
The error you are getting is because there is no `initialize()` function. If you declare one there will be no error. 

```
function loadScript() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
    document.body.appendChild(script);
    console.log('loadScript');
}

function initialize() {
    console.log('initialize');
}

window.onload = loadScript;

```
> 
> I tried to run it in JSFidle and there where no problems.
> 
> 
> 

Incorrect. On JSFiddle you have a *different* problem.

There you run your code when the document load event fires. That code defines a function and assigns an event handler for the document load event. Since that event has already fired, the function never runs. You don't get an error because the code doesn't get as far as it does when you test in your standalone document.

> 
> When I run it on my html page which runs on a demo server I get the following error in the console:
> 
> 
> 

In this case, the code is running successfully.

The load event fires. The loadScript function runs. The script element is appended to the page. Google's script runs.

You get an error because you said:

> 
> 
> ```
>  'callback=initialize'
> 
> ```
> 
> 

So the script you are requesting from Google tries to call `initialize()`, but you haven't defined that function so you get an error instead.

See also [the documentation](https://developers.google.com/maps/documentation/javascript/tutorial) which includes this example:

```
function initialize() {
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644)
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
}

function loadScript() {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
      '&signed_in=true&callback=initialize';
  document.body.appendChild(script);
}

window.onload = loadScript;

```