简体   繁体   中英

How to catch OleObject exception in Inno Setup?

So I try to make a post request having no internet connection using next modified code:

      WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
      WinHttpReq.Open('POST', '<your_web_server>', false);
      WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      try
        WinHttpReq.Send('data');
      except
           bla:= 'e';
      finally
           bla := 'f';
      end;

Yet exception does not get catched and I get crush of my setup application with next image:

在此输入图像描述

How to handle OleObject exception in Inno Setup?

Your code is incomplete, but try..except block catches all the exceptions, including those thrown by OLE objects. However, your screenshot shows the line number, where the exception was thrown, and so you were running debugger.

And debugger shows all exception messages regardless they are in a try..except block, unless you uncheck "Pause on exceptions" option in Inno Setup IDE settings:

在此输入图像描述

By default is this option enabled (which I would recommend to keep), which means that all exceptions are reported as exception messages and that's what might have mislead you. If you were running your setup without debugger attached, you wouldn't see that exception message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM