TXNLEVEL()
that would report the nested level of TRY-CATCH block?>>>* declare >>>PUBLIC g_TRYLEVEL && or ADDPROP(_SCREEN.TRYLEVEL) >>> >>>g_TRYLEVEL = 0 >>> >>>* on every TRY/ENDTRY >>> >>>TRY >>> g_TRYLEVEL = m.g_TRYLEVEL +1 >>> ..... >>> >>>FINALLY >>> g_TRYLEVEL = m.g_TRYLEVEL -1 >>> ..... >>>ENDTRY >>>>>
>>define class myclass as custom >> >> funciton method2() as Logical >> local llSuccess as Logical >> local loE as Exception >> try >> &&do something.... >> if not this.method1() ; >> then >> throw && this moves the execution pointer to catch block >> endif >> m.llSuccess = .t. >> catch to loE >> &&log the error and/or report to the user >> m.llSuccess = .f. >> exit >> finally >> if m.llSuccess ; >> then >> //do something >> else >> //do something else >> endif >> endtry >> return m.llSuccess >> endfunc &&method2 >> >> funciton method1() as Logical >> local llSuccess as Logical >> local loE as Exception >> try >> &&do something.... >> m.llSuccess = .t. >> catch to loE >> &&log the error and/or report to the user >> m.llSuccess = .f. >> && throw && this does not escalate it to try-catch in method2 it loops >> exit >> finally >> endtry >> return m.llSuccess >> endfunc &&method1 >> >>enddefine >>>>I was hoping that when I throw exception from method1 it would be caught by TRY-CATCH in method2. However that's not the case, it loops in the same TRY-CATCH instead of escalating it to the higher level handler which is defined in method2.
>SET TEXTMERGE noSHOW off >CLEAR > >mc=CREATEOBJECT("myclass") >rvalue=mc.method2() >? rvalue > >define class myclass as custom > > function method2() as Logical > local llSuccess as Logical > local loE as Exception > try > &&do something.... > llSuccess = this.method1() > ? "do something" > catch to loE > &&log the error and/or report to the user > ? "do something WHEN ERROR" > ? > finally > endtry > return m.llSuccess > endfunc &&method2 > > function method1() as Logical > local llSuccess as Logical > local loE as Exception > try > ERROR "CATCH THIS" > llSuccess = .t. > catch to loE > ? MESSAGE() > > &&log the error and/or report to the user > throw && this does not escalate it to try-catch in method2 it loops > endtry > return m.llSuccess > endfunc &&method1 > >enddefine >Fabio,
SET TEXTMERGE noSHOW off CLEAR SET STEP ON mc=CREATEOBJECT("myclass") rvalue=mc.method2() ? rvalue define class myclass as custom function method2() as Logical local llSuccess as Logical local loE as Exception try &&do something.... llSuccess = this.method1() ? "do something" catch to loE &&log the error and/or report to the user ? "do something WHEN ERROR" ? finally endtry return m.llSuccess endfunc &&method2 function error(errorno as Integer,method as String,lineno as Integer) as VOID messagebox("Hello, I'm your error!") endfunc && error function method1() as Logical local llSuccess as Logical local loE as Exception try ERROR "CATCH THIS" llSuccess = .t. catch to loE ? MESSAGE() this.Error(loE.ErrorNo,loE.Procedure,loE.LineNo) &&log the error and/or report to the user throw && this does not escalate it to try-catch in method2 it loops endtry return m.llSuccess endfunc &&method1 enddefine
"Do not let any unwholesome talk come out of your mouths,
but only what is helpful for building others up according to their needs,
that it may benefit those who listen."
- Ephesians 4:29-30 NIV
Dare to Question -- Care to Answer
Time is like water in a sponge, as long as you are willing you can always squeeze some.
--Lu Xun, Father of Modern Chinese Literature