public static void Main() { try { ExceptionClass.Raise(); } catch (ExceptionClass e) { Console.Out.WriteLine("Excpected Exception"); Console.Out.WriteLine(e); } var firstCatch = true; try { ExceptionClass.RaiseNotImplemented(); } catch (NotImplementedException e) when(firstCatch) { Console.Out.WriteLine("Excpected Exception"); Console.Out.WriteLine(e); } catch (NotImplementedException e) { // Rethorw the exception as it throw; } finally { } }
public void LogException(string type, string exceptionDescription, Exception exception) { try { string fullExceptionDescription = t.PrintException(exceptionDescription, exception); if (fullExceptionDescription.Contains("Message :Core is not running")) { return; } LogLogic(new LogEntry(-1, type, fullExceptionDescription)); ExceptionClass exCls = new ExceptionClass(fullExceptionDescription, DateTime.Now); exceptionLst.Add(exCls); int sameExceptionCount = CheckExceptionLst(exCls); int sameExceptionCountMax = 0; foreach (var item in exceptionLst) { if (sameExceptionCountMax < item.Occurrence) { sameExceptionCountMax = item.Occurrence; } } } catch { } }
/* Sprawdza czy istnieje wystarczająca ilość miejsca do dodania tekstu do pliku */ private static bool isEnoughSpace(String Text, int lastFileBlockID) { int freeCharactersInLastDisc = Disc.howManyFreeCharacters(lastFileBlockID); int length = Text.Length - freeCharactersInLastDisc; if (length < 0) { return(true); } else if (freeCharactersInLastDisc == Text.Length) { return(true); } bool wynik = freeBlocks.isEnoughFreeBlocks(length); if (wynik) { return(true); } else { ExceptionClass.returnExceptionMessage("Brak miejsca na dysku"); return(false); } }
public void DemoExceptions() { Console.WriteLine("-----------------Exceptions Example-----------------"); ExceptionClass exceptionClass = new ExceptionClass(7, 0, 9); exceptionClass.PrintArea(); }
public void SetProperties(Acompanhamento acompanhamento) { ExceptionClass.Exec(string.IsNullOrEmpty(acompanhamento.Nome), "Campo nome é obrigatório"); this.Nome = acompanhamento.Nome.Trim(); this.Data = this.Id != Guid.Empty ? acompanhamento.Data : DateTime.Now; this.StatusCardapio = StatusCardapio.ATIVO; }
/* Sprawdza czy plik istnieje */ public static bool checkIfFileExist(String fileName) { bool wynik = folder.checkIfFileExist(fileName); if (!wynik) { ExceptionClass.returnExceptionMessage("Plik o podanej nazwie nie istnieje."); } return(wynik); }
public void Validation(Marmita marmita) { ExceptionClass.Exec(marmita.Mistura == null, "Mistura é obrigatória"); ExceptionClass.Exec(marmita.Salada == null, "Salada é obrigatória"); ExceptionClass.Exec(marmita.Valor < 0, "Valor inválido"); ExceptionClass.Exec(marmita.Mistura.AcrescimoValor < 0, "Valor inválido"); ExceptionClass.Exec(marmita.Acompanhamentos.Count() > 2, "Proibido mais de dois acompanhamentos em uma marmita"); ExceptionClass.Exec(marmita.Tamanho.ToString().Equals(string.Empty), "Tamanho inválido"); ExceptionClass.Exec(marmita.Pedido.Cliente == null, "Cliente inválido"); }
/* Zapisuje plik na dysku fizycznym o nowej nazwie */ public void printToExternalFile(String fileName, String newFileName) { String TextToWrite = Controller.printFile(fileName); using (var streamWriter = new StreamWriter(newFileName + ".txt")) { streamWriter.WriteLine(TextToWrite); ExceptionClass.returnExceptionMessage("Zapisano plik na dysk fizyczny. Nazwa pliku: " + newFileName); } }
/*======================Metody pomocnicze======================*/ /* Sprawdzenie długości nazwy pliku */ public static bool checkFileNameLength(String FileName) { if (FileName.Length > FileNameLength) { ExceptionClass.returnExceptionMessage("Podana nazwa jest za długa"); return(false); } else { return(true); } }
/* Sprawdza czy istnieje wystarczająca ilość wolnych bloków */ public static bool isEnoughFreeBlocks(String Text) { bool wynik = freeBlocks.isEnoughFreeBlocks(Text); if (wynik) { return(true); } else { ExceptionClass.returnExceptionMessage("Brak miejsca na dysku"); return(false); } }
public void Validation(Cliente cliente) { ExceptionClass.Exec(string.IsNullOrEmpty(cliente.Nome), "Campo nome é obrigatório"); ExceptionClass.Exec(string.IsNullOrEmpty(cliente.Sexo.ToString()), "Escolha uma opção de sexo"); ExceptionClass.Exec(string.IsNullOrEmpty(cliente.Rua), "O campo rua é obrigatório"); ExceptionClass.Exec(cliente.RuaNumero <= 0, "O campo número da rua é obrigatório"); ExceptionClass.Exec(string.IsNullOrEmpty(cliente.Bairro), "O campo bairro é obrigatório"); ExceptionClass.Exec(string.IsNullOrEmpty(cliente.NumeroCasa), "O campo número da casa é obrigatório"); ExceptionClass.Exec(string.IsNullOrEmpty(cliente.Telefone), "O campo telefone é obrigatório"); ExceptionClass.Exec(cliente.Telefone.Length != 14, "Telefone inválido"); if (cliente.Celular != null && cliente.Celular.Length > 0) { ExceptionClass.Exec(cliente.Celular.Length != 15, "Celular inválido"); } }
private int CheckExceptionLst(ExceptionClass exceptionClass) { int count = 0; #region find count try { //remove Exceptions older than an hour for (int i = exceptionLst.Count; i < 0; i--) { if (exceptionLst[i].Time < DateTime.Now.AddHours(-1)) { exceptionLst.RemoveAt(i); } } //keep only the last 12 Exceptions while (exceptionLst.Count > 12) { exceptionLst.RemoveAt(0); } //find court of the same Exception if (exceptionLst.Count > 0) { string thisOne = t.Locate(exceptionClass.Description, "######## EXCEPTION FOUND; BEGIN ########", "######## EXCEPTION FOUND; ENDED ########"); foreach (ExceptionClass exCls in exceptionLst) { string fromLst = t.Locate(exCls.Description, "######## EXCEPTION FOUND; BEGIN ########", "######## EXCEPTION FOUND; ENDED ########"); if (thisOne == fromLst) { count++; } } } } catch { } #endregion exceptionClass.Occurrence = count; LogStandard(t.GetMethodName("Log"), count + ". time the same Exception, within the last hour"); return(count); }
/// <summary> /// Generates exception classes in the model namespaces for exceptions declared in the service model. /// </summary> /// <param name="operation">The operation to generate exceptions for</param> void GenerateExceptions(Operation operation) { this.ExecuteGenerator(new BaseServiceException(), "Amazon" + this.config.BaseName + "Exception.cs"); foreach (var exception in operation.Exceptions) { // Check to see if the exceptions has already been generated for a previous operation. if (!this.processedStructures.Contains(exception.Name)) { var generator = new ExceptionClass() { Exception = exception, GenerateComplexException = this.config.ServiceModel.Customizations.GenerateComplexException }; this.ExecuteGenerator(generator, exception.Name + ".cs", "Model"); this.processedStructures.Add(exception.Name); } } }
private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); ProgramData programdata = new ProgramData(); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ExceptionClass.UIException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionClass.BGException); ProgramData progdat = new ProgramData(); new MAIN(progdat); try{ Application.Run(new launcher(progdat)); }catch (Exception e) { ExceptionClass.ExceptReporter(e); } }
/* Pobiera tekst z pliku fizycznego i tworzy nowy plik o nowej nazwie */ public void readFromExternalFile(String fileName, String newFileName) { String Text = ""; if (Controller.checkFileNameExist(newFileName) && Controller.checkFileNameLength(newFileName)) { try { using (var streamWriter = new StreamReader(fileName + ".txt")) { Text = streamWriter.ReadToEnd(); if (Controller.isEnoughFreeBlocks(Text)) { Controller.addNewFile(newFileName, Text); ExceptionClass.returnExceptionMessage("Odczytano plik z dysku fizycznego. Utworzono plik o nazwie: " + newFileName); } } } catch (Exception ex) { } } }
/// <summary> /// Generates exception classes in the model namespaces for exceptions declared in the service model. /// </summary> /// <param name="operation">The operation to generate exceptions for</param> void GenerateExceptions(Operation operation) { this.ExecuteGenerator(new BaseServiceException(), "Amazon" + this.Configuration.BaseName + "Exception.cs"); foreach (var exception in operation.Exceptions) { // Check to see if the exceptions has already been generated for a previous operation. if (!this._processedStructures.Contains(exception.Name)) { var generator = new ExceptionClass() { Exception = exception, GenerateComplexException = this.Configuration.ServiceModel.Customizations.GenerateComplexException }; this.ExecuteGenerator(generator, exception.Name + ".cs", "Model"); this._processedStructures.Add(exception.Name); } } }
public void NoStacktraceTest() { var w = new ExceptionClass(); w.NoStacktrace(); }
public void WithStacktraceTest() { var w = new ExceptionClass(); w.WithStacktrace(); }
/// <summary> /// Generates exception classes in the model namespaces for exceptions declared in the service model. /// </summary> /// <param name="operation">The operation to generate exceptions for</param> void GenerateExceptions(Operation operation) { foreach (var exception in operation.Exceptions) { // Skip exceptions that have already been generated for the parent model if (IsExceptionPresentInParentModel(this.Configuration, exception.Name)) continue; // Check to see if the exceptions has already been generated for a previous operation. if (!this._processedStructures.Contains(exception.Name)) { var baseException = string.Format("Amazon{0}Exception", this.Configuration.IsChildConfig ? this.Configuration.ParentConfig.BaseName : this.Configuration.BaseName); var generator = new ExceptionClass() { Exception = exception, GenerateComplexException = this.Configuration.ServiceModel.Customizations.GenerateComplexException, BaseException = baseException }; this.ExecuteGenerator(generator, exception.Name + ".cs", "Model"); this._processedStructures.Add(exception.Name); } } }
public void Validation(Pedido pedido) { ExceptionClass.Exec(pedido.Total < 0, "Total da compra inválido"); ExceptionClass.Exec(pedido.Cliente == null, "É necessário um cliente para efetuar a compra"); ExceptionClass.Exec(pedido.Marmitas == null || pedido.Marmitas.Count == 0, "Para efetuar a compra precisa de pelo menos uma marmita adicionada"); }
public static extern int StSetLastError( ExceptionClass type, int code, string message);
/// <summary> /// Sets the last error information for the calling thread. The value /// can be retrieved with StGetLastError(). /// </summary> /// <param name="type">The type of the exception, which determines how /// to interpret the error code. Set this to EcUser for /// user-defined error codes.</param> /// <param name="code">One of the pre-defined error codes or a /// user-defined one, depending on the exception type.</param> /// <param name="message">Optional pointer to an error message. This /// parameter can be \c null.</param> public static void StSetLastError(ExceptionClass type, int code, string message) { NativeMethods.StSetLastError(type, code, message); }
public void Validation(Mistura mistura) { ExceptionClass.Exec(string.IsNullOrEmpty(mistura.Nome), "Campo nome é obrigatório"); ExceptionClass.Exec(mistura.AcrescimoValor < 0, "Valor não pode ser menor que zero"); }
public void Validation(Salada salada) { ExceptionClass.Exec(string.IsNullOrEmpty(salada.Nome), "Campo nome é obrigatório"); }
public void Validation(MarmitaAcompanhamento marmita) { ExceptionClass.Exec(marmita == null, "Marmita inválida"); ExceptionClass.Exec(marmita.AcompanhamentoId == 0, "Acompanhamento é obrigatório"); }
public void Validation(Acompanhamento t) { ExceptionClass.Exec(string.IsNullOrEmpty(Nome), "Nome não pode ser vazio"); ExceptionClass.Exec(Nome.Length < 3, "Nome não pode ter menos que 3 caracteres"); ExceptionClass.Exec(Nome.Length > 30, "Nome não pode ter mais que 30 caracteres"); }