REQUEST A DEMO

ClearBasic cbbatch tip: Display the line number of the most recent error

After over a decade of doing ClearBasic coding, I’m still learning new things.

 

Today, Marek pointed out the Erl function, which returns the line number of the most recent error.

 

Within the Clarify Client, if you use the –debugCB option, you’ll get the line number of the last CB error, so it’s pretty easy there.

 

But in cbbatch, it doesn’t tell you the line number.

Error message, no line number

 

For example, I have a simple cbbatch script that I’ve coded with an error.

error

 

Notice how it tells me the error, but it doesn’t tell me *where* the error is.

 

Let caveman debugging commence. Ugh.

More error details

 

Now, lets add a simple error handler.

 

At the beginning of my routine, I add an On Error statement:

On Error Goto ErrorHandler

 

And then at the end of my routine, I add the Error Handler label and code.

ErrorHandler:
Debug.Print “ERROR”
Debug.Print “Source: ” &  Err.Source
Debug.Print “Line Number: ” & Erl
Debug.Print “Error Number: ” & Err.Number
Debug.Print “Description: ” & Err.Description

 

Now when I run my script, I get more information, including the exact line number that caused the error:

error_number

 

There’s the error – on line 39!  Now my debugging becomes that much easier.

Hooray Erl!

 

I need to make this error handler part of my standard boilerplate for cbbatch scripts.

 

Perhaps I knew of Erl at some point, but I either forgot, or it’s just been part of my mission to eradicate ClearBasic code from my life.

 

Perhaps blogging it will bring it back into my memory. Or at least Google’s memory.

 

For all you ClearBasic coders out there (all 17 of you) – hope you find this useful.

 

Rock on.