Two ways:

1.
Code:
if ($sock(ophours)) { ; display custom error and return }


2.
Code:
sockopen ophours ... ...
return
:error
var %err = * /sockopen: 'ophours' socket in use (line 96, xxHour-Panel)
if ($error == %err) {
  ; Display custom error
  reseterror
}