-
Notifications
You must be signed in to change notification settings - Fork 182
/
magick_wand_exception.go
51 lines (43 loc) · 1.22 KB
/
magick_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
50
51
// 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 <MagickWand/MagickWand.h>
*/
import "C"
import (
"fmt"
"runtime"
"unsafe"
)
type MagickWandException struct {
kind ExceptionType
description string
}
func (mwe *MagickWandException) Error() string {
return fmt.Sprintf("%s: %s", mwe.kind.String(), mwe.description)
}
// Clears any exceptions associated with the wand
func (mw *MagickWand) clearException() bool {
return 1 == C.int(C.MagickClearException(mw.mw))
}
// Returns the kind, reason and description of any error that occurs when using other methods in this API
func (mw *MagickWand) GetLastError() error {
var et C.ExceptionType
csdescription := C.MagickGetException(mw.mw, &et)
defer relinquishMemory(unsafe.Pointer(csdescription))
if ExceptionType(et) != EXCEPTION_UNDEFINED {
mw.clearException()
return &MagickWandException{ExceptionType(C.int(et)), C.GoString(csdescription)}
}
runtime.KeepAlive(mw)
return nil
}
func (mw *MagickWand) getLastErrorIfFailed(ok C.MagickBooleanType) error {
if C.int(ok) == 0 {
return mw.GetLastError()
} else {
return nil
}
}