Exception.Create() problem in ISAPI Web DLL

Good Morning:
I am currently converting my Delphi Win32 application to ISAPI DLL Web Server Application.

I have done some experiments with Exception.Create function in both projects:

For Delphi Win32 application, Exception.Create() function generate  dialog box with OK button, once i click that OK button, it exits from all the functions/procedures and return nothing.
This is how Exception works ..(see attached code: Part A)

But, for ISAPI DLL Web Server Applications, it return me the "Internal Server Error", i know it is because the dialog box problem ....(see attached code: Part B)

my question is :
is there anyway to use other function instead of Exception.Create() in my DLL project so that wherenever exception is met, my DLL can exit from all the functions/procedures without generating an error?

thanks

Part A:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if TestFunction then
    showmessage('hello');
end;

function TForm1.TestFunction:Boolean;
  procedure RaiseException(const msg : string);
  begin
    raise Exception.Create(msg);
  end;

var
  a : integer;
begin
  result := false;
  a := 1;
  if a = 1 then
    RaiseException('Wrong Data');
  result := true;
end;


Part B:
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  if TestFunction then
    response.content := 'testing completed';
end;

function TWebModule1.TestFunction:Boolean;
  procedure RaiseException(const msg : string);
  begin
    raise Exception.Create(msg);
  end;

var
  a : integer;
begin
  result := false;
  a := 1;
  if a = 1 then
    raiseexception('Wrong Data');
  result := true;
end;
chongkeng_woonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pierre CorneliusCommented:
You can catch the exception and respond accordingly, e.g.:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  try
    if TestFunction then
      response.content := 'testing completed';
  except on e: exception do
      response.content:= 'error: '+e.message;
  end;
end;


Another way is to do it without using exceptions, like this:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  if TestFunction
    then response.content := 'testing completed'
    else response.content := 'error: test function failed'; //or 'wrong data' or whatever
end;

function TWebModule1.TestFunction:Boolean;
var
  a : integer;
begin
  result := false;
  a := 1;
  result:= (a <> 1);
//  if a = 1 then
//    raiseexception('Wrong Data');
//  result := true;
end;

I prefer the exception method as it is easier to specify numerous problem/messages from a single function.

Regards
Pierre
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.