ta4e
ta4e

Reputation: 1

Display dialog causing error

I have a simple dialog. The user can either accept the dialog or cancel it. But when I cancel, it errors. Why?

try
    display dialog "I cause an error when my 'cancel' button is pressed."
on error error_message number error_number
    display dialog "Error: " & error_number & ":" & error_message & "."
end try

Upvotes: 0

Views: 134

Answers (2)

fireshadow52
fireshadow52

Reputation: 6516

The Cancel button always causes an error in the display dialog command. You cannot fix that. However, if you do as @regulus6633 suggested and specify the buttons yourself, you won't have to worry about errors.

Upvotes: 0

regulus6633
regulus6633

Reputation: 19030

Here's one that doesn't error!

display dialog "I won't cause an error because I specified the buttons myself and didn't include a cancel button!" buttons {"Quit", "OK"} default button 2

Upvotes: 1

Related Questions