rediffusion
11/2/2017 - 4:39 PM

Отлов ошибок try и catch

Немного инфы в WORD - Вопрос-Ответ (поддержка)

//OwnCodeUsings в 'Общий код':
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Text.RegularExpressions;
using ZennoLab.CommandCenter;
using ZennoLab.InterfacesLibrary;
using ZennoLab.InterfacesLibrary.ProjectModel;
using ZennoLab.InterfacesLibrary.ProjectModel.Collections;
using ZennoLab.InterfacesLibrary.ProjectModel.Enums;
using ZennoLab.Macros;
using Global.ZennoExtensions;
using ZennoLab.Emulation;
 
namespace ZennoLab.OwnCode
{
    /// <summary>
	/// A simple class of the common code
	/// </summary>
	public class CommonCode
	{
		/// <summary>
		/// Lock this object to mark part of code for single thread execution
		/// </summary>
		public static object SyncObject = new object();
 
		// Insert your code here
		
		public static string Test (string strTest) {
			try{
				strTest = strTest.ToUpper();
				return Test2(strTest);
			}catch{
				return "ИСПРАВЛЕНО!!!";
			}
		}
		
		private static string Test2 (string strTest) {
			if (strTest.Contains("ПРОВЕРКА")) throw new Exception("не люблю проверки!!!");
			return strTest + "!!!!!";
		}
	}
}
try{
    
	project.SendInfoToLog(CommonCode.Test("проверка"));
	
	List<HtmlElement> lstTest = instance.ActiveTab.FindElementsByXPath("//test").ToList();
	
	HtmlElement elTest = lstTest[2];
	if (lstTest.Count==0) {
			
	}
	
	
}catch(Exception e){
	if (e.Message.Contains("за пределами")) {
		project.SendErrorToLog("Не создан список аккаунтов");
	}else{
		project.SendErrorToLog("Неизвестная ошибка" + e.Message);
	}
	
}finally{
	project.SendInfoToLog("finally");
}

return "oki";