V10 ResourcesReference
ResourcesReference
Reference
Back | List of Articles

How to use the "HandleExceptions" and "Handled" properties in the events?

Last changed in 02/07/2020

With the new extensibility engine, unlike VBA, it is possible to have several implementations to one single event. These implementations are coded in extensions recorded in the ERP and the execution order of the subscribed events is defined by the record order or using the Order (using the namespace Primavera.Extensibility.Attributes) if the events are in the same extension.

The following example shows the event AntesDeGravar of the FichaArtigos, subscribed more than once in the same extension:

using Primavera.Extensibility.Attributes;

public class UiFichaArtigos1 : FichaArtigos
{
	[Order(0)]
	public override void AntesDeGravar(ref bool Cancel, ExtensibilityEventArgs e)
	{
		base.AntesDeGravar(ref Cancel, e);
	}
}

public class UiFichaArtigos2 : FichaArtigos
{
	[Order(1)]
	public override void AntesDeGravar(ref bool Cancel, ExtensibilityEventArgs e)
	{
		base.AntesDeGravar(ref Cancel, e);
	}
}

This way, it is possible to have an execution pile for the same event, which allows to manage the exceptions that occur in two different ways:

  • Cancel the form operation and the subscribed event(s) execution;
  • Continue the form operation and show only one user message with exception error data.

This procedure is controlled by the property value "HandleExceptions":

ValueBehavior
TrueThe exceptions that were not handled in the implementation should be handled by the ERP.

The form operation is not interrupted and, finally, the system presents an information error message on the exception.

FalseThe exceptions that were not handled in the implementation should be handled by the ERP.

The form operation is cancelled.

By default, this property assumes the value "True" for all Platform event implementations and the value "False" for the remaining.

When the exceptions move to the following events, they are available in the property Exceptions. The following example shows how an exception that is not controlled and occurs in the first event subscription pass to the next event.

public class UiFichaArtigos1 : FichaArtigos
{
	[Order(0)]
	public override void AntesDeGravar(ref bool Cancel, ExtensibilityEventArgs e)
	{
		e.HandleExceptions = true;
		throw new Exception("Erro ao gravar na extensão 1.");
	}
}

public class UiFichaArtigos2 : FichaArtigos
{
	[Order(1)]
	public override void AntesDeGravar(ref bool Cancel, ExtensibilityEventArgs e)
	{
		string msg = "UiFichaArtigos2.AntesDeGravar" + Environment.NewLine;
		msg += string.Format("Exceções: {0}", e.Exceptions.Count);

		if (e.Exceptions.Count > 0)
		{
			foreach (var item in e.Exceptions)
			{
				msg += "Exceção = " + item.Exception.Message + Environment.NewLine;
			}
		}

		PSO.Dialogos.MostraMensagem(StdPlatBS100.StdBSTipos.TipoMsg.PRI_SimplesOk, msg);
	}
}

You can still define the value "True" for the property "Handled" to intervene and cancel the event implementation pile execution at any moment.

From the video Exception Handling we can see both properties being used together to control the exceptions and the pile execution.

Bookmark or share this article
Esta página foi útil?
Obrigado pelo seu voto.

login para deixar a sua opinião.

Obrigado pelo seu feedback. Iremos analisá-lo para continuarmos a melhorar!
Artigos Relacionados
Características das entidades e serviços Conceito de integração Conceito de extensibilidade Como registar projetos de extensibilidade? Boas práticas de organização de projetos de integração
Últimos Artigos Vistos
How to process employee earnings using the API?How to create employees using the API?