Exception in a Method, Block Format?

I’m working with Xojo 2016r3, on a Mac, for a Mac. If I’m writing a method and then want to add some kind of exception handling, my code might look like this…

// Method goes here

Exception
MsgBox(“Error Message”)
Quit

What I notice is that when I type Exception, Xojo’s very helpful auto-formatting (sorry if that’s not the right word) tries to indicate that I’m beginning a block of code (shows a red right triangle at the beginning of the block of code), and it shows the proper end of the code has NOT yet been typed yet. For instance, if I were to type an “If”, that would start a block of code, and the auto-formatting would keep reminding me I’m not done until it sees an “End”.

Is there a proper way to end the Exception block of code…or do you just leave things with a block of code that seems to indicate it’s unfinished (it does compile and work)?

Thanks!

Yes

Stylistically while this is “valid” its probably not the best style

Usually you should use try / catch and then list the specific exceptions you expect to catch rather than “everything” which is what you have done with a single “exception” at the end of the method like this

But if you intend to catch each and every possible exception, you could add your own Error Handler to the UnhandledException Event of the App Object of your Projects.

Thanks to all who replied. Much appreciated. (I do have more complicated error handling than shown, but my example was obviously just a quickie for illustrative purposes.) I thought maybe I was missing an “End” on the Exception…which, if I added it, seemed to satisfy the auto-formatting but then I got an error on compile that the “End” shouldn’t be there.