BOOL Exceptions

When BOOL gets into trouble at run-time it throws an Exception. Such problems include resource issues (like a missing file) or code issues (such as when a Model can’t find an Action to handle a received Message).

There are a some native Exceptions, but user code often extends those for the sake of the application (following a common model used in Java, Python, and many other languages).

A BOOL Exception is a special kind of Model, so the syntax for a definition of one looks similar to the Model definition syntax:

.   *string  ErrorMessage = get:@Sys,ERROR,TEXT
.   *int     ErrorCode    = get:@Sys,ERROR,CODE

That’s the as if definition of the native base Exception Model. BOOL initializes the member Instances at run-time when it generates the Exception Instance.

The Exception hierarchy has an #Error Model at its top. The next level down contains the #Exception Model and the #System Model, both of which extend #Error.

User-defined Exceptions extend #Exception if no binding is specified, but with a binding may extend any extension of #Exception. The #System Model cannot be extended — all such extensions are by the system (#FileNotFound, for example).

For example:

.   *int  Line-Number
.   *string  Source-Text-Line

##Syntax-Missing-Parenthesis <#Syntax-Error>
.   *string Caption = "Missing Parenthesis!"

At run-time, during an Exception, the RTE searches the current Call Frame for object Instances that match the names specified in the Exception and binds any found to the Exception fields (if there is an initializer, no binding occurs).

In the example above, presumably some sort of compiler, if BOOL can find a Line-Number or Source-Text-Line object in the current CF, it binds them to the #Syntax-Error Exception.

To throw an Exception in code, just refer to it:

@if bad-thing-happened
.   #Bad-Thing-Exception

Exceptions are caught by Exception handlers:

@@Bad-Thing-Handler <#Bad-Thing-Exception>
.   {{bad thing handler code}}

(I’m actually not happy with that; it needs development… Ideally I want to bind an Exception handler with an Action that might experience that Exception. For example, binding #Exception to @Main would catch any uncaught unextended Exceptions thrown in that Action and in any called Actions.)

((Part of why some of this is vague is that I really need to write some actual BOOL code to get a sense of what I really want from certain parts of it. It’s only recently that I’ve settled certain matters regarding how the code looks that enables me to really start thinking about this.))

So, anyway, there’s a little about BOOL Exceptions.

%d bloggers like this: