External Exception $406D1388 in Delphi

 Delphi  Comments Off on External Exception $406D1388 in Delphi
Aug 012020
 

Reminder to self: Exception $406D1388 is the exception used to set a name for a thread, like in:

procedure SetThreadName(const _Name: AnsiString);
var
  ThreadNameInfo: TThreadNameInfo;
begin
  ThreadNameInfo.FType := $1000;
  ThreadNameInfo.FName := PAnsiChar(_Name);
  ThreadNameInfo.FThreadID := $FFFFFFFF;
  ThreadNameInfo.FFlags := 0;
  try
    RaiseException($406D1388, 0, SizeOf(ThreadNameInfo) div SizeOf(LongWord), Pointer(@ThreadNameInfo));
  except
    // ignore
  end;
end;

If you encounter this in a debugging session, simply add it to the OS Exceptions and set “Handled by” to “User program” and “On Resume” to “Run handled” (The program should handle it, it’s a bug if not. But we don’t want to see it at all.)

 Posted by on 2020-08-01 at 19:30