-
Notifications
You must be signed in to change notification settings - Fork 2
/
cat_func_error_handler.pro
76 lines (61 loc) · 2.47 KB
/
cat_func_error_handler.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
COMPILE_OPT idl2, HIDDEN
; Get the ErrorLevel
IF (Obj_IsA_Valid (self, 'CatAtom')) THEN errorLevel = self._errorLevel $
ELSE errorLevel = CatGetDefault ('ErrorLevel', Success=ok)
IF (errorLevel EQ 0) THEN errorLevel = 2 ; default is to pop up a dialog
; Set up the Catch error handler (unless catch is inhibited)
IF (errorLevel LT 3) THEN Catch, theError $
ELSE theError = 0
; If an error has occurred ...
IF theError NE 0 THEN $
BEGIN
; Cancel the error handler and set up the error handling to "throw" error
CATCH, /Cancel
; If this is a standard CATATOM object method, report it's failed
IF (Obj_IsA_Valid (self, 'CatAtom')) THEN self -> Report, /Failed
; Get the call stack.
HELP, Calls=callstack
callingRoutine = (StrSplit(StrCompress(callStack[1])," ", /Extract))[0]
HELP, /Last_Message, Output=msg
ON_ERROR, 2
; If the error has been previously handled, don't handle it here
positions = StrPos(msg, '[cat_handled]')
foundit = Where(positions NE -1, count)
IF count GT 0 THEN $
BEGIN
msg[0] = '[cat_handled]'
IF Scope_Level() GT 2 THEN MESSAGE, msg[0] ELSE RETURN, 0
END
; Report the error
IF (Obj_IsA_Valid (self, 'CatAtom')) THEN self -> Error $
ELSE CASE errorLevel OF
1 : BEGIN
Print, ''
Print, 'Traceback Report from ' + StrUpCase(callingRoutine) + ':'
Print, ''
FOR j=0,N_Elements(msg)-1 DO Print, " " + msg[j]
END
2 : BEGIN
junk = Dialog_Message(msg[0])
Print, ''
Print, 'Traceback Report from ' + StrUpCase(callingRoutine) + ':'
Print, ''
FOR j=0,N_Elements(msg)-1 DO Print, " " + msg[j]
END
ELSE : BEGIN
Print, ''
Print, 'Traceback Report from ' + StrUpCase(callingRoutine) + ':'
Print, ''
FOR j=0,N_Elements(msg)-1 DO Print, " " + msg[j]
END
ENDCASE
; Throw the error, signalling that it's already been handled
IF Scope_Level() GT 2 $
THEN MESSAGE, msg[0] + ' [cat_handled]' $
ELSE BEGIN
Message, /RESET
RETURN, 0
ENDELSE
ENDIF
; If this is a standard CATATOM object method, report it's start
IF (Obj_IsA_Valid (self, 'CatAtom')) THEN self -> Report, /Started