Exception Error in SubMethod

I’m surprise and I don’t think it was like that in previous Xojo version.

I have a button with the code in its Pressed event:

Dim f_Elt as FolderItem
Dim TampText as String

f_Elt = SpecialFolder.Documents
TampText = f_Elt.NativePath
MessageBox "Button1" + EndOfLine + TampText

AsubMethod


Exception TypErr
  
  Beep
  MessageBox "Button1 Err" + EndOfLine + TypErr.Message

.
In the Method AsubMethod I have the code (with an error):

Dim f_Elt as FolderItem
Dim TampText as String

f_Elt = Nil ' SpecialFolder.Documents
TampText = f_Elt.NativePath
MessageBox "AsubMethod" + EndOfLine + TampText

.
As the error is in the sub method, I would have the generic Xojo error, in a buit application I would have a crash. Instead of that the error is managed in the button event.
I read the doc and I’m not sure to understand how it is suppose to be managed.
Xojo doc exception

Exemple project: ExceptErr-SubMethod.proj

This is behaving correctly in 2022r3 and has not changed from previous versions. The catch statement will catch any exception raised within scope (which includes submethods as you’re seeing).

This is why using a catch-all is bad. You lose granularity over what you are handling and can handle things incorrectly.

If you would like to avoid catching exceptions within the submethod, you’ll need to be more specific about where you are catching exceptions from.

try
  
  Dim f_Elt as FolderItem
  Dim TampText as String
  
  f_Elt = SpecialFolder.Documents
  TampText = f_Elt.NativePath
  MessageBox "Button1" + EndOfLine + TampText
  
catch TypErr as TypeOfException
// Do not catch RuntimeException as mentioned moments ago
  
  Beep
  MessageBox "Button1 Err" + EndOfLine + TypErr.Message
  
end try
// Now that the try...catch has closed, the method below will raise an uncaught exception
// which will bubble to the App.UnhandledException event

AsubMethod