Data.GraphViz.Exception

graphviz-2999.18.1.0: Bindings to Graphviz for graph visualisation.

Copyright | (c) Ivan Lazar Miljenovic
License | 3-Clause BSD-style
Maintainer | Ivan.Miljenovic@gmail.com
Safe Haskell | Safe
Language | Haskell2010

Data.GraphViz.Exception

Contents

- Re-exported for convenience.

Description

Synopsis

- data GraphvizException
  - = NotDotCode String
  - | NotUTF8Dot String
  - | GVProgramExc String
  - | NotCustomAttr String
- mapException :: (Exception e1, Exception e2) => (e1 -> e2) -> a -> a
- throw :: Exception e => e -> a
- handle :: Exception e => (e -> IO a) -> IO a -> IO a
- bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c

# Documentation

data GraphvizException

Exceptions that arise from using this library fall into four categories:

- Unable to parse provided Dot code.
- Dot code is not valid UTF-8.
- An error when trying to run an external program (e.g. `dot`).
- Treating a non-custom Attribute as a custom one.

Constructors

NotDotCode String |
NotUTF8Dot String |
GVProgramExc String |
NotCustomAttr String |

Instances

Eq GraphvizException |
Ord GraphvizException |
Show GraphvizException |
Exception GraphvizException |

# Re-exported for convenience.

mapException :: (Exception e1, Exception e2) => (e1 -> e2) -> a -> a

This function maps one exception into another as proposed in the paper "A semantics for imprecise exceptions".

throw :: Exception e => e -> a

Throw an exception. Exceptions may be thrown from purely functional code, but may only be caught within the `IO` monad.

handle :: Exception e => (e -> IO a) -> IO a -> IO a

A version of `catch` with the arguments swapped around; useful in situations where the code for the handler is shorter. For example:

      do handle (\NonTermination -> exitWith (ExitFailure 1)) $
         ...

bracket

Arguments

:: IO a | computation to run first ("acquire resource")
-> (a -> IO b) | computation to run last ("release resource")
-> (a -> IO c) | computation to run in-between
-> IO c |

When you want to acquire a resource, do some work with it, and then release the resource, it is a good idea to use `bracket`, because `bracket` will install the necessary exception handler to release the resource in the event that an exception is raised during the computation. If an exception is raised, then `bracket` will re-raise the exception (after performing the release).

A common example is opening a file:

    bracket
      (openFile "filename" ReadMode)
      (hClose)
      (\fileHandle -> do { ... })

The arguments to `bracket` are in this order so that we can partially apply it, e.g.:

    withFile name mode = bracket (openFile name mode) hClose