Return statement sometimes not working
Posted: Thu Feb 11, 2016 4:29 pm
Greetings,
I have a large application with about 15 forms.
Each of these forms has a click event on it which processes information provided on the form.
These click events often have quite a number of try/catch blocks in them.
In many cases the catch block writes an error to a logfile and to the window and issues a return statement e.g.:
try
{
Add-MailboxPermission -Identity $Mailbox.distinguishedname -User $Group.distinguishedname -AccessRight FullAccess -InheritanceType All -DomainController $ActiveSiteDC -ErrorAction Stop
}
Catch
{
Catcherror $_ "ERROR: Granting Full Access to [$MBGroupName]" $Mailbox
$formCreateMailboxes.cursor = "default"
return
}
The user running the application sees the error message and is free to fix the problem and continue. So in most cases the Return statement simply does what it should and goes to the end of the click event function and returns control to the end user.
However....
In one form, the return statements simply exit the catch block and continue processing the click event function code.
Why would this be?
Thanks
David Z
I have a large application with about 15 forms.
Each of these forms has a click event on it which processes information provided on the form.
These click events often have quite a number of try/catch blocks in them.
In many cases the catch block writes an error to a logfile and to the window and issues a return statement e.g.:
try
{
Add-MailboxPermission -Identity $Mailbox.distinguishedname -User $Group.distinguishedname -AccessRight FullAccess -InheritanceType All -DomainController $ActiveSiteDC -ErrorAction Stop
}
Catch
{
Catcherror $_ "ERROR: Granting Full Access to [$MBGroupName]" $Mailbox
$formCreateMailboxes.cursor = "default"
return
}
The user running the application sees the error message and is free to fix the problem and continue. So in most cases the Return statement simply does what it should and goes to the end of the click event function and returns control to the end user.
However....
In one form, the return statements simply exit the catch block and continue processing the click event function code.
Why would this be?
Thanks
David Z