I am using www to fetch a url. I want to catch timeouts in a try-trap
block. I believe I am following the exact same syntax in the tests for
the package but it still throws an error.
package req www
set url ...
% try {www get $url} trap {WWW DATA TIMEOUT} {msg info} {puts timeout} couldn't open socket: connection timed out
% try {www get $url} trap {WWW TIMEOUT} {msg info} {puts timeout}
couldn't open socket: connection timed out
Any suggestion to make this work? Is there a list of codes to trap?
On 20/07/2025 20:04, saito wrote:
Any suggestion to make this work? Is there a list of codes to trap?
You can add an "on error" handler to find out the error code for
different cases:
package require www
set url http://10.10.10.10/
try {
www get $url
} trap {WWW DATA TIMEOUT} {msg info} {
puts timeout
} on error {msg info} {
puts "Unexpected error: [dict get $info -errorcode]"
}
Running that will show that the error code for this specific failure is:
WWW CONNECT {couldn't open socket: connection timed out}
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 163:53:33 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
9,181 files (2,736M bytes) |
Messages: | 2,411,516 |