os_generate_error and postmortems

Jonathan Coxhead jonathan at doves.demon.co.uk
Tue Aug 24 21:15:21 BST 2004


    Stefan Bellon wrote:

> Ok, so let me rephrase my question. What's the proper way of doing what
> the following short BASIC program does:
> 
> DIM err% 256
> 
> !err% = 0
> $(err%+4) = "foobar"+CHR$0
> 
> SYS "OS_GenerateError", err%
> 
> If you save this to a file and then start the BASIC file from within a
> TaskWindow, then the error message is printed in the TaskWindow. If you
> double-click on the file in the Filer, then the error appears in an
> error box.

    BASIC installs an error handler for SIGOSERROR. The code it runs in the 
error handler checks to see if it is a Wimp task and then either calls 
Wimp_ReportError or OS_WriteS. In C using the "goto finish" style, you'd have to 
do that in your app, in the error handler section:

       int main()
       {
           os_error *err = NULL;

           /* body of code */
           ...

           /* handle errors */
           if (err != NULL)
           {
               if (wimpreadsysinfo_desktop_state() == wimpreadsysinfo_STATE_DESKTOP)
                   xwimp_report_error (err, ...);
               else
                   fprintf (stderr, "%s\n", err->errmess);

               return 1;
           }
           else
               return 0;
       }

    I'm not sure that's the best way to detect the presence of the Wimp---we 
want something that's true for a real Wimp task, but false for a utility running 
outside the desktop or in a command window or a task window. Maybe someone more 
current than I am could comment on that ...

    ... cheers ...

... J

> I'd like to achieve the same effect from within a C program that uses
> OSLib. Initially I thought os_generate_error is the way to go. Is there
> another way?
> 
> TIA.




More information about the oslib-user mailing list