How to handle the run Time Error in MagickWand

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Locked
ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

How to handle the run Time Error in MagickWand

Post by ArunKumar »

How to Handle the RunTime Error in MagickWand?

Is there Any Way to Handle the RunTime Error in MagickWand

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to handle the run Time Error in MagickWand

Post by snibgo »

Yes. These are called "exceptions". See your question in viewtopic.php?f=6&t=37772
snibgo's IM pages: im.snibgo.com

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to handle the run Time Error in MagickWand

Post by ArunKumar »

snibgo wrote:
2020-04-02T21:34:55-07:00
Yes. These are called "exceptions". See your question in viewtopic.php?f=6&t=37772
For Example :In java there is Exception Handling Concept which has TryCatch Block to handle the run time error
Is There Any Such Way to Handle the run time errors in MagickWand API(C Language)?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to handle the run Time Error in MagickWand

Post by snibgo »

The cpp language has "try {...} catch {...}". The C language does not.
snibgo's IM pages: im.snibgo.com

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to handle the run Time Error in MagickWand

Post by ArunKumar »

snibgo wrote:
2020-04-03T03:58:07-07:00
The cpp language has "try {...} catch {...}". The C language does not.
Hence How to handle the exception caused by MagickWand API in C Language

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to handle the run Time Error in MagickWand

Post by magick »

Here's one way:

Code: Select all

#define ThrowAPIException(wand) \
{ \
  description=MagickGetException(wand,&severity); \
  (void) FormatLocaleFile(stderr,"%s %s %lu %s\n",GetMagickModule(), \
    description); \
  description=(char *) MagickRelinquishMemory(description); \
  exit(-1); \
}
...
  MagickWandGenesis();
  magick_wand=NewMagickWand();
  status=MagickReadImage(magick_wand,path);
  if (status == MagickFalse)
    ThrowAPIException(magick_wand);
...

Locked