Using SmartInspect with madExcept

Inspired by our recent article about using EurekaLog together with SmartInspect, SmartInspect user Jeremy Brown ported our example to madExcept and kindly provided us with screenshots and sample code.

The example project demonstrates how to attach an event handler to madExcept and add a SmartInspect log file to madExept’s crash report whenever an unhandled exception occurs:

uses
  madExcept;

// [...]

procedure ExceptionHandler(const ExceptIntf: IMEException;
    var Handled: Boolean);
const
  ZIPFILE = 'CrashReport.zip';
var
  LStream   : TFileStream;
  LTempPath : array[0..MAX_PATH+1] of Char;
  LFileName : String;
begin
  Handled := False;

  { Get a temporary filename }
  if GetTempPath(MAX_PATH, LTempPath) = 0 then
    Exit;

  // Save madShi's bug report information in the log.
  SiMain.LogException(Exception(ExceptIntf.ExceptObject),
    'Madshi Exception Handler');
  SiMain.LogString('BugReport', ExceptIntf.BugReport);

  ExceptIntf.AdditionalAttachments.Clear;

  { Put everything in a zip file }
  ExceptIntf.ScreenShotZip := ZIPFILE;
  ExceptIntf.BugReportZip  := ZIPFILE;

  { Just some extra optional information }
  ExceptIntf.AdditionalFields.Add('Application',
    Application.Title);

  LFileName := IncludeTrailingPathDelimiter(LTempPath) +
    'CrashLog.sil';
  { Save the log file }
  LStream := TFileStream.Create(LFileName, fmCreate);
  try
    Si.Dispatch('mem', 0, LStream);
  finally
    LStream.Free;
  end;

  { Attach the file to madShi's crash report }
  ExceptIntf.AdditionalAttachments.Add(LFileName, '', ZIPFILE);
end;

initialization
  RegisterExceptionHandler(ExceptionHandler,
    stTrySyncCallOnSuccess);
end.

The resulting madExcept email and crash report zip file includes a SmartInspect log file with the recent user actions and application data, along with madExcept’s error report and screenshot:

If you are already using madExcept and are planning to integrate it with SmartInspect (or the other way around), Jeremy’s example code is a great starting point and should get you up and running in a few minutes. You can download the example code here and learn more about the used techniques in the related EurekaLog article.

This entry was posted in DelphiFeeds.com, Gurock Software, Programming, SmartInspect and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

  1. By MadExcept (and SmartInspect) - Steffen On Delphi on December 18, 2008 at 22:58

    [...] like the application name and version number. Since we use SmartInspect we add this log file (here is another example of this)  to the report as well as another log generated by our burning engine. SmartInspect-Logging in [...]

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting