Caudium HOWTO
Prev | Chapter 6. Developing with Caudium | Next

# 6.5. How to use a backtrace

A backtrace is text that will show you where your program come before the error. This is very useful for developers when they debug. The best is to take an example. Did you try the who module at the end of Section 6.4? If so take it and check it works. Now change the line `string command = QUERY(path2who)+" "+QUERY(options2who);` to `string command = 0;`. This will create an error because we put an int into a string. If we want to do that, we have to cast it (for example, use (string) 0). If you have not done it yet, press the `More options` button in the CIF. and reload the module. Check that the `Global Variables` -> `show_internals` option is set to yes, and try your module. You will have an error which should look like this:

    Caudium version: Caudium (Caudium/1.2.0)
    Requested URL: /who

    Error: Sprintf: Wrong type for argument 2: expected string, got int.
    ../local/modules/who.pike:76:
    CaudiumModule(Who,My first virtual server)->find_file("",object)
    base_server/configuration.pike (version 1.91):1587:
    Configuration(My first virtual server)->low_get_file(object,0)
    base_server/configuration.pike (version 1.91):1779:
    Configuration(My first virtual server)->get_file(object,0)
    base_server/configuration.pike (version 1.91):1760:
    Configuration(My first virtual server)->handle_request(object)
    protocols/http.pike (version 1.71):1549: unknown function()
    protocols/http.pike (version 1.71):1610:
    unknown function(0,"GET /who HTTP/1.1\r\nHost: localhost\r\nUser-Agent:
    Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8)
    Gecko/20020214\r\nAccept: text/xml,application/xml,
    application/xhtml+xml,text/html;q=0.9,text/plain"+[246])
    /usr/local/pike/7.2.262/lib/modules/Stdio.pmod/module.pmod
    (version 1.114):683:
    Stdio.File("socket", "127.0.0.1 1260", 777 /* fd=-1 */)
    ->__stdio_read_callback()

This seems awful but it is not. The first line is the error in itself:

    "Error: Sprintf: Wrong type for argument 2: expected string, got int."
    The next line "../local/modules/who.pike:76:
    CaudiumModule(Who,My first virtual server)->find_file("",object)"
    is the program (../local/modules/who.pike at line 76)

where the error occurred. `find_file` is the name of the function where the error occurred and you have also the arguments given to it. If you use the source, you see mixed find_file(string path, object id). So here path="" and id=object [1]. Next line is the function (`low_get_file` in `configuration.pike`) that has called `find_file` in `who.pike`. You also have its arguments and so on. This backtrace is very useful when the error doesn't come directly from your code but from another code before.

### Notes

[1] | Pike can't display contents of an object but can display any other types.

Prev | Home | Next
Your first module | Up | How to print something to debug log file