简体   繁体   English

寻找除了或最后的尝试

[英]Finding the try for an except or finally

I'm dealing with some code that has fantastically long methods (10k lines!) and some odd use of try-finally and try-except blocks. 我正在处理一些具有非常长的方法(10k行!)和一些奇怪的try-finally和try-except块的代码。 Some of the latter are long by themselves, and don't always have the try at the start of the method. 后者中的一些本身很长,并且在方法开始时并不总是尝试。

Obviously I'm trying to refactor the code, but in the meantime just being able to fix a couple of common pathologies would be much easier if I could jump to the start of a block and see what is happening there. 显然我正在尝试重构代码,但与此同时,如果我能够跳到块的开头看看那里发生了什么,那么能够修复几个常见的病理就会容易得多。 When it's 20+ pages away finding it even with the CNPack rainbows ("code structure highlight") is just tedious. 当它超过20页时,即使使用CNPack彩虹(“代码结构突出显示”)也能找到它只是单调乏味。

I'm using D2010 and have GExperts (with DelForExp), CNPack and DDevExtensions installed, but I can't find anything that lets me jump from the try to the finally or back. 我正在使用D2010并安装了GExperts(使用DelForExp),CNPack和DDevExtensions,但我找不到任何可以让我从试用跳到最后或者回来的东西。 Am I missing something? 我错过了什么吗? Is there another add-in that I can use that will get me this? 是否有另外一个我可以使用的插件会让我这个?

GExperts have it in Editor Experts: "Move to Matching Delimiter", with the keyboard shortcut Ctrl+Alt+Right by default. GExperts在编辑专家中使用它:“移动到匹配分隔符”,默认情况下使用键盘快捷键Ctrl + Alt + Right。 If you invoke it repeatedly it cycles from try to the matching finally or except , to end , then back to try , and so on. 如果从调用它反复它的周期try到匹配finallyexcept ,到end ,然后回到try ,等等。

If you are going to refactor the code, I'd advice you to name each Try Except/finally End code block and move it into a separate function/procedure within the main method. 如果您要重构代码,我建议您为每个Try Except / finally End代码块命名,并将其移动到main方法中的单独函数/过程中。

Second advice, start with the inner most try except/finally end code block. 第二条建议,从最内部尝试开始,除了/ finally结束代码块。

procedure class1.method1 ;
var
   anyVariables : ... ;
begin
 ....
 try 
 ....
 finally
 ... 
 end ;
 ....
end ;

.

procedure class1.method1 ;
var
   anyVariables : ... ;
   procedure first_try_finally_block ;
   begin 
      try 
      ....
      finally
      ... 
      end ;
   end ;
begin
 ....
 first_try_finally_block
 ....
end ;

I hope that this will help you to solve your problem. 我希望这能帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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