This document provides development guidelines and other information for contributors to the Pig project.

Error Handling

There are several types of errors in Pig:

It is helpful to be able to separate different types of errors in our code. Here is the proposal on how to handle them:

As a general rule, follow the custom of the current source file when throwing new Exceptions. When in doubt, enquire with other developers on the mailing list.

Using the exception classes

The PigException and its subclasses have an extensive suite of constructors. The important constructors are noted below:

  1. PigException (String message, int errCode, byte errSrc)

  2. PigException (String message, int errCode, byte errSrc, Throwable cause)

A couple of examples will illustrate the point.

   1 throw new PigException("Expected bytearray but received int", 1300, PigException.INPUT);
   3 //alternatively
   4 int errCode = 1300;
   5 String msg = "Expected bytearray but received int";
   6 throw new PigException(msg, errCode, PigException.INPUT);
   8 try {
   9 ...
  10 } catch (RemoteException re) {
  11    throw new PigException("Internal error. Caught some other exception", 5500, PigException.REMOTE_ENVIRONMENT, re);
  12 }
  14 //alternatively
  15 try {
  16 ...
  17 } catch (RemoteException re) {
  18    int errCode = 5500;
  19    String msg = "Internal error. Caught some other exception";
  20    throw new PigException(msg, errCode, PigException.REMOTE_ENVIRONMENT, re);
  21 }

Pig and Eclipse

To use Pig with the Eclipse IDE, see Eclipse_Environment.


  1. Santhosh Srinivasan, "Pig Error Handling Functional Specification" January 23, 2009, http://wiki.apache.org/pig/PigErrorHandlingFunctionalSpecification

PigDeveloperCookbook (last edited 2009-09-20 23:38:32 by localhost)