How to use the "HandleExceptions" and "Handled" properties in the events?
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: 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: This procedure is controlled by the property value "HandleExceptions": The form operation is not interrupted and, finally, the system presents an information error message on the exception. 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. 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.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);
}
}
Value Behavior True The exceptions that were not handled in the implementation should be handled by the ERP. False The exceptions that were not handled in the implementation should be handled by the ERP. 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);
}
}
login para deixar a sua opinião.