unit ExceptionUtils;

interface
uses
	SysUtils;

type
	ECustom = class(Exception);

procedure throw(const anException: Exception; const aPreviousExceptionMessage: string = ''); overload;
procedure throw(const aMessage: string; const aPreviousExceptionMessage: string = ''); overload;
procedure throw(const aMessage: string;	const anArgs: array of const;
	const aPreviousExceptionMessage: string = ''); overload;

implementation

procedure throw(const anException: Exception; const aPreviousExceptionMessage: String); overload;
begin
	anException.Message := Format('%s[%s]%s',	[^J^M, anException.ClassName, anException.Message]);
	if aPreviousExceptionMessage <> '' then
		anException.Message := Format('%s%s',	[anException.Message, aPreviousExceptionMessage]);

	raise anException;
end;

procedure throw(const aMessage: string; const aPreviousExceptionMessage: String); overload;
begin
	throw(ECustom.Create(aMessage), aPreviousExceptionMessage);
end;

procedure throw(const aMessage: string;	const anArgs: array of const;
	const aPreviousExceptionMessage: String); overload;
begin
	throw(Format(aMessage, anArgs), aPreviousExceptionMessage);
end;

end.
