#############################################################################

[main]

[main - data:]

# method (for information only: the program scans the file name)
method: ERROR

[main - header:]

/* prototypes */

void my_error_handler( const char *objid, const char *file, int line, 
		       const char *errortype, int errorcode, const char *reason );

\#define COMPARE_SAMPLE_SIZE  (500)
\#define VIOLATE_SAMPLE_SIZE   (20)

#############################################################################

[new]

#############################################################################

# [set]

#############################################################################

# [get]

#############################################################################

# [chg]

#############################################################################

# [init]

#############################################################################

# [reinit]

#############################################################################

# [sample]

#############################################################################

# [validate]

#############################################################################

[special]

[special - decl:]

GCC_DIAG_OFF(unused-but-set-variable)

  double fpm[2] = {0., -1.};
  UNUR_DISTR *distr = NULL;
  UNUR_ERROR_HANDLER *default_error_handler = NULL;

[special - start:]

  /* invoke default error handler */
  distr = unur_distr_normal(fpm,2);

  /* change error handler */
  default_error_handler = unur_set_error_handler( my_error_handler );
  distr = unur_distr_normal(fpm,2);

  /* change to old error handler */
  default_error_handler = unur_set_error_handler( default_error_handler );
  distr = unur_distr_normal(fpm,2);

  /* change to new error handler again */
  default_error_handler = unur_set_error_handler( default_error_handler );
  distr = unur_distr_normal(fpm,2);

  /* change to default error handler */
  default_error_handler = unur_set_error_handler( NULL );
  distr = unur_distr_normal(fpm,2);

  /* switch off error reporting */
  default_error_handler = unur_set_error_handler_off();
  distr = unur_distr_normal(fpm,2);

  /* change to old error handler */
  default_error_handler = unur_set_error_handler( default_error_handler );
  distr = unur_distr_normal(fpm,2);

  /* test finished */
  FAILED = 0;

GCC_DIAG_ON(unused-but-set-variable)


#############################################################################

[verbatim]

void my_error_handler( const char *objid, const char *file, int line, 
                       const char *errortype, int errorcode, const char *reason )
     /*----------------------------------------------------------------------*/
     /* parameters:                                                          */
     /*   objid     ... id/type of object                                    */
     /*   file      ... file name (inserted by __FILE__)                     */
     /*   line      ... line number in source file (inserted by __LINE__)    */ 
     /*   errortype ... "warning" or "error"                                 */
     /*   errorcode ... UNU.RAN error code                                   */
     /*   reason    ... (very) short description of reason for error         */
     /*----------------------------------------------------------------------*/
{
  FILE *LOG = UNURANLOG;
  static int n = 0;

  fprintf(LOG,"\n");
  fprintf(LOG,"[[ %d ]] my_error_handler:  [ %s ]\n",++n,errortype);
  fprintf(LOG,"\tobject = %s\n",objid);
  fprintf(LOG,"\tfile   = %s\n",file);
  fprintf(LOG,"\tline   = %d\n",line);
  fprintf(LOG,"\tcode   = [%\#x] %s\n",errorcode,unur_get_strerror(errorcode));
  fprintf(LOG,"\treason = %s\n",reason);
  fprintf(LOG,"\n");

} /* end of my_error_handler() */


#############################################################################
