Author Topic: UIButton.OnClick() error handling  (Read 5265 times)

mulova

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
UIButton.OnClick() error handling
« on: August 18, 2014, 09:42:35 PM »
All UIButtons are not responsive after the UIButton.onClick EventDelegates throws error.
It's because UIButton.current is not null afterward.

  1.         protected virtual void OnClick ()
  2.         {
  3.                 if (current == null && isEnabled)
  4.                 {
  5.                         current = this;
  6.                         try {
  7.                                 EventDelegate.Execute(onClick);
  8.                         } finally {
  9.                                 current = null;
  10.                         }
  11.                 }
  12.         }
  13.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton.OnClick() error handling
« Reply #1 on: August 19, 2014, 10:59:44 AM »
Ideally the try/catch block should be inside EventDelegate.Execute to cover all cases. Still, you shouldn't have exceptions in your code to begin with, they can lead to all kinds of problems.

mulova

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UIButton.OnClick() error handling
« Reply #2 on: August 21, 2014, 08:24:23 PM »
You are absolutely right. But there may be exceptional cases hardly found.
And Programmers like me always make mistakes.  :(
If all the buttons doesn't work in real situation it would be like hell.
I think exception handling makes NGUI robust.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton.OnClick() error handling
« Reply #3 on: August 22, 2014, 03:54:50 AM »
Yup, which is why I already added the try/catch block to the EventDelegate.Execute back when I wrote that last reply. ;)