madExcept Demo 

www.madshi.net

Let's look at a little demo, consisting of one tiny application and an even tinier DLL. The application's project file looks like this:

{01} program CrashApp;
{02}
{03} uses
{04}   madExcept,
{05}   madLinkDisAsm,
{06}   Forms,
{07}   CrashUnit in 'CrashUnit.pas' {CrashForm};
{08}
{09} {$R *.RES}
{10}
{11} begin
{12}   Application.Initialize;
{13}   Application.CreateForm(TCrashForm, CrashForm);
{14}   Application.Run;
{15} end.

As you can see, there's nothing to speak about, just one unit with a form. The unit looks like this:

{01} unit CrashUnit;
{02}
{03} interface
{04}
{05} uses
{06}   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
{07}   Dialogs, StdCtrls;
{08}
{09} type
{10}   TCrashForm = class(TForm)
{11}     CrashButton: TButton;
{12}     procedure CrashButtonClick(Sender: TObject);
{13}   private
{14}     { Private-Deklarationen }
{15}   public
{16}     { Public-Deklarationen }
{17}   end;
{18}
{19} var
{20}   CrashForm: TCrashForm;
{21}
{22} implementation
{23}
{24} {$R *.DFM}
{25}
{26} procedure CrashDllProc; external 'crashDll.dll';
{27}
{28} procedure CrashProc;
{29} begin
{30}   CrashDllProc;
{31} end;
{32}
{33} procedure TCrashForm.CrashButtonClick(Sender: TObject);
{34} begin
{35}   CrashProc;
{36} end;
{37}
{38} end.

You can see that we have one button, which when being clicked on calls a function in our DLL. Furthermore we've enabled madExcept support for our project in the madExcept settings dialog, which results in "madExcept" and "madLinkDisAsm" being automatically added to the project's uses clause. That's all. Now let's see how the DLL looks like:

{01} library CrashDll;
{02}
{03} uses madExcept, madLinkDisAsm, SysUtils;
{04}
{05} {$R *.RES}
{06}
{07} procedure CrashDllProc;
{08} begin
{09}   integer(nil^) := 0;
{10} end;
{11}
{12} exports CrashDllProc;
{13}
{14} end.

The DLL does nothing but export one function, which raises an access violation, when being called. Okay, now let's compile both projects, run the application, press the button and see what happens. Point the mouse at the tabs of the window to see the contents of the other tabs.

If we follow the call stack from the bottom to the top we begin with line 14 in the project, which is the line "Application.Run". The next stack item in our own sources is the line in "TCrashForm.CrashButtonClick", where the "CrashProc" is called. In between we can follow the way in which the code walked from the message loop in "Application.Run" to our button click event handler. Okay, the next stack item in our sources is the line in "CrashProc", where the function from the DLL is called. Finally we're reaching the real exception location, which is inside of the DLL.

This demo is very short and easy just to give you a first idea of how madExcept works. If you want to see a more detailed and complicated demo, please look in the "Demos" folder of your madExcept installation or directly download the ExcCatch demo.