-
Notifications
You must be signed in to change notification settings - Fork 181
/
drawing_wand_exception.go
49 lines (41 loc) · 1.18 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
47
48
49
// Copyright 2013 Herbert G. Fischer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package imagick
/*
#include <wand/MagickWand.h>
*/
import "C"
import (
"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 relinquishMemory(unsafe.Pointer(csdescription))
if ExceptionType(et) != EXCEPTION_UNDEFINED {
dw.clearException()
return &DrawingWandException{ExceptionType(C.int(et)), C.GoString(csdescription)}
}
return nil
}
func (dw *DrawingWand) getLastErrorIfFailed(ok C.MagickBooleanType) error {
if C.int(ok) == 0 {
return dw.GetLastError()
} else {
return nil
}
}