Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppleScript: on error (try) line number

Is it possible to get the line number, where the script threw an error?

Example:

try
    set a to "abc" + "123"
 on error line number num
    display dialog "Error on line number " & num
end try
like image 360
Tyilo Avatar asked May 12 '11 12:05

Tyilo


2 Answers

i don't think so try statements look like this

try
    set a to "abc" + "123"
 on error errMsg
    display dialog "ERROR: " & errMsg
end try

but you could look at script debugger which will show you what line your error occurred on

another alternative is to get textmate which goes for $52 when it errors it gives you the line number and is also useful for writing code in many languages

like image 116
mcgrailm Avatar answered Sep 28 '22 09:09

mcgrailm


Actually the on error syntax include the error number also (but no line number):

try
    set a to "abc" + "123"
on error errorMessage number errorNumber
    log ("errorMessage: " & errorMessage & ", errorNumber: " & errorNumber)
end try

You can use semaphores to mark your progress:

try
    ... your code here ...

    set lineNumber to "17"

    ... more code here

    set lineNumber to "18"

    ... more code here

on error errorMessage number errorNumber
    log ("(line #" & lineNumber & ") errorMessage: " & errorMessage & ", errorNumber: " & errorNumber)
end try

And I'll 2nd mcgrailm's recommendation for Script Debugger!

like image 28
geowar Avatar answered Sep 28 '22 09:09

geowar