-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdrawing_wand_exception.go
46 lines (39 loc) · 1.05 KB
/
drawing_wand_exception.go
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
package gmagick
/*
#include <wand/wand_api.h>
*/
import "C"
import (
"errors"
"fmt"
"unsafe"
)
type DrawingWandException struct {
kind ExceptionType
description string
}
func (dwe *DrawingWandException) Error() string {
return fmt.Sprintf("%s: %s", dwe.kind.String(), dwe.description)
}
// Clears any exceptions associated with the wand
func (dw *DrawingWand) clearException() bool {
return 1 == C.int(C.DrawClearException(dw.dw))
}
// Returns the kind, reason and description of any error that occurs when using other methods in this API
func (dw *DrawingWand) GetLastError() error {
var et C.ExceptionType
csdescription := C.DrawGetException(dw.dw, &et)
defer C.MagickRelinquishMemory(unsafe.Pointer(csdescription))
if ExceptionType(et) != EXCEPTION_UNDEFINED {
dw.clearException()
return &DrawingWandException{ExceptionType(C.int(et)), C.GoString(csdescription)}
}
return errors.New("undefined exception")
}
func (dw *DrawingWand) getLastErrorIfFailed(ok C.uint) error {
if ok == 0 {
return dw.GetLastError()
} else {
return nil
}
}