Blitz3D+ Command Reference

JobErrorLine ( job )

Parameters

job - a Job handle returned by StartJob

Description

Returns the one-based source line retained for a failed job, or 0.

This is the line-number half of the worker failure diagnostics: combined with JobErrorFile and JobErrorFunction it points at the code that was executing when the Worker Function's runtime error was raised. Worker failures never open the GUI debugger, so logging these three plus JobError is the standard way to make background failures diagnosable.

It returns a meaningful line only while JobState is JOB_FAILED; for every other state it returns 0.

For the full story, see the Using Background Jobs guide.

Requires Extended mode.

See also: JobError, JobErrorFile, JobErrorFunction, JobState.

Example

; JobErrorLine Example
; --------------------
; Requires Extended mode.

Graphics 640,480,0,2
SetBuffer BackBuffer()

; This worker fails on purpose while loading a corrupted save file
Worker Function LoadCorruptSave(inputBank)
    SetJobProgress 1L,2L,"Verifying checksum"
    ; Busy work standing in for real parsing
    For parse=1 To 4000000
        noise#=Sin(parse)
    Next
    ; The checksum does not match - fail the Job deliberately
    RuntimeError "Save file checksum mismatch"
    Return CreateBank()
End Function

job=StartJob(LoadCorruptSave)

While Not KeyDown(1)

    Cls

    Text 0,0,"Esc: exit"
    Text 70,160,"Loading save file on a worker thread..."

    If JobState(job)=JOB_FAILED
        ; JobErrorLine reports the one-based line of the RuntimeError above
        Text 70,210,"JobErrorLine(job) = "+JobErrorLine(job)
        Text 70,240,"JobError(job) = "+Chr(34)+JobError(job)+Chr(34)
        Text 70,270,"Zero is returned for Jobs that did not fail"
    Else
        Text 70,210,"Still loading..."
    EndIf

    Flip

Wend

FreeJob job
End

Index