How to catch OleObject exception in Inno Setup?

时间秒杀一切 提交于 2019-12-23 12:54:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22039048/how-to-catch-oleobject-exception-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!