Which Routine Raises This Exception
To find every place a Delphi project raises or catches one exception type, drag-lint has a verb, exception-facts, that lists one row per raise or handler site and says how it knows the type.
The verb arrived in drag-lint 1.50.0-alpha and is in drag-lint 1.51.2-alpha, the current public release. Every output below is real output of 1.51.2-alpha, run on the small fixture in section 01 (file paths shortened). The verb reads facts from the index, so index the project first.
Sooner or later someone asks: where does this exception come from, and who deals with it? Before changing EDataError we want every raise of it and every on E: EDataError do. Micronite, the quality and production-control software we build for manufacturers, has exception classes that many units raise, so a text search for the class name returns declarations, comments and string literals along with the sites we want.
Two units that raise, one that catches
Three small units and a project file. Errs declares EDataError and its child EMissingFile. Work.Load raises both; Work.Run calls Load, catches each, and re-raises the first.
unit Work;
...
procedure Load(const pName: string);
begin
if pName = '' then
raise EMissingFile.Create('no name');
if pName = 'x' then
raise EDataError.Create('bad');
end;
procedure Run;
begin
try
Load('a');
except
on E: EMissingFile do
Writeln('missing');
on E: EDataError do
raise;
end;
end;
Ask by routine, then by type
Step 1. Index the project.
drag-lint index --project P.dproj --db fx.sqlite
Done. Files: 3, Symbols: 10, Refs: 22, 0.47s, parse-errors=0
Step 2. Ask what one routine raises and handles. --target takes a qualified routine or its trailing part.
drag-lint exception-facts --target Load --db fx.sqlite
raises Errs.EMissingFile bound Work.Load (Work.pas:11:11)
raises Errs.EDataError bound Work.Load (Work.pas:13:11)
2 exception fact(s)
drag-lint exception-facts --target Run --db fx.sqlite
handles Errs.EMissingFile bound Work.Run (Work.pas:21:11)
handles Errs.EDataError bound Work.Run (Work.pas:23:11)
reraises Errs.EDataError handler Work.Run (Work.pas:24:7)
3 exception fact(s)
One row per site: the action, the type, how the type is known, the routine and the position.
Step 3. Ask the other way: every site for one type. --name takes a bare or a qualified type name.
drag-lint exception-facts --name EDataError --db fx.sqlite
raises Errs.EDataError bound Work.Load (Work.pas:13:11)
handles Errs.EDataError bound Work.Run (Work.pas:23:11)
reraises Errs.EDataError handler Work.Run (Work.pas:24:7)
3 exception fact(s)
Step 4. Read the third column. bound means the resolver bound the site to an indexed type, the strongest answer. handler is the type of the enclosing on ... do, which is how the bare raise; on line 24 gets EDataError. Other values mark weaker answers, down to unknown when nothing tells.
Raise and handler sites are indexed facts
The index records each raise and each handler as a row with its routine and position. The resolver then binds the type name to a declared type. That is why the rows above carry Errs.EDataError rather than the spelling, and why a text search for EDataError is not needed. A raise; and a raise E; inside a handler take the handler's type.
What exception-facts does not tell you
The verb lists sites, not paths. It has no ancestry: in step 3 the raise of the child EMissingFile on line 11 is absent from the EDataError answer, and an on E: Exception handler would not be listed under EDataError either, though it catches one. It has no callers: Run re-raises EDataError from its handler, but a routine that lets a callee's exception pass is not listed as raising it. For where an exception ends up through the callers, the verb's help points to ask exception-paths. A raise Make; where Make is a function returning an Exception is listed as raises-expr with no type and unknown in the third column: the type is only known at run time.