Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.pig;
 
 
All exceptions in Pig are encapsulated in the PigException class. Details such as the source of the error, error message, error code, etc. are contained in this class. The default values for the attributes are: errorSource = BUG errorCode = 0 retriable = false detailedMessage = null location = null
 
 public class PigException extends IOException {
 
 	// Change this if you modify the class.
 	static final long serialVersionUID = 1L;
 
     /*
      * Instead of using an enum for the source of the error,
      * the classic style of using static final is adopted
      */
     public static final byte INPUT = 2;
     public static final byte BUG = 4;
     public static final byte USER_ENVIRONMENT = 8;
     public static final byte REMOTE_ENVIRONMENT = 16;
     public static final byte ERROR = -1;

    
A static method to query if an error source is due to an input or not.

Parameters:
errSource - byte that indicates the error source
Returns:
true if the error source is an input; false otherwise
 
     public static boolean isInput(byte errSource) {
         return ((errSource & ) == 0 ? false : true);
     }

    
A static method to query if an error source is due to a bug or not.

Parameters:
errSource - byte that indicates the error source
Returns:
true if the error source is a bug; false otherwise
 
     public static boolean isBug(byte errSource) {
         return ((errSource & ) == 0 ? false : true);
     }

    
A static method to query if an error source is due to the user environment or not.

Parameters:
errSource - byte that indicates the error source
Returns:
true if the error source is due to the user environment; false otherwise
 
     public static boolean isUserEnvironment(byte errSource) {
         return ((errSource & ) == 0 ? false : true);
     }

    
A static method to query if an error source is due to the remote environment or not.

Parameters:
errSource - byte that indicates the error source
Returns:
true if the error source is due to the remote environment; false otherwise
 
     public static boolean isRemoteEnvironment(byte errSource) {
         return ((errSource & ) == 0 ? false : true);
     }
    
    
A static method to determine the error source given the error code

Parameters:
errCode - integer error code
Returns:
byte that indicates the error source
 
    public static byte determineErrorSource(int errCode) {
    	if(errCode >= 100 && errCode <= 1999) {
    		return .;
    	} else if (errCode >= 2000 && errCode <= 2999) {
    		return .;
    	} else if (errCode >= 3000 && errCode <= 4999) {
    	} else if (errCode >= 5000 && errCode <= 6999) {
    	}
    	return .;
    }
    
    protected int errorCode = 0;
    protected byte errorSource = ;
    protected boolean retriable = false;
    protected String detailedMessage = null;
    protected boolean markedAsShowToUser = false;
    protected SourceLocation sourceLocation = null;


    
Create a new PigException with null as the error message.
    public PigException() {
        super();
    }
    
    
Create a new PigException with the specified message.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
    public PigException(String message) {
        super(message);
    }
    
    
Create a new PigException with the specified message.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
location - The <link>SourceLocation</link> that generated this error.
    public PigException(String messageSourceLocation location) {
        super(message);
         = location;
    }
    
    
Create a new PigException with the specified cause.

Parameters:
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
    public PigException(Throwable cause) {
        super(cause);
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
    public PigException (String messageThrowable cause) {
        super(messagecause);
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
    public PigException (String messageint errCode) {
        this(message);
         = errCode;
    }
    
    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
location - The <link>SourceLocation</link> that generated this error.
    public PigException (String messageint errCodeSourceLocation location) {
        this(messagelocation);
         = errCode;
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
    public PigException (String messageint errCodeThrowable cause) {
        this(messagecause);
         = errCode;
    }
    
    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
location - The <link>SourceLocation</link> that generated this error.
    public PigException (String messageint errCodeThrowable causeSourceLocation location) {
        this(messagecause);
         = errCode;
         = location;
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
    public PigException (String messageint errCodebyte errSrc) {
        this(messageerrCode);
         = errSrc;
    }
    
    
    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
location - The <link>SourceLocation</link> that generated this error.
    public PigException (String messageint errCodebyte errSrcSourceLocation location) {
        this(messageerrCodelocation);
         = errSrc;
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
    public PigException (String messageint errCodebyte errSrcThrowable cause) {
        this(messageerrCodeerrSrcfalsenullcause);
    }
    
    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
location - The <link>SourceLocation</link> that generated this error.
    public PigException (String messageint errCodebyte errSrcThrowable causeSourceLocation location) {
        this(messageerrCodeerrSrcfalsenullcauselocation);
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
retry - If the exception is retriable or not
    public PigException (String messageint errCodeboolean retry) {
        this(messageerrCode);
         = retry;
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
retry - If the exception is retriable or not
    public PigException (String messageint errCodebyte errSrcboolean retry) {
        this(messageerrCodeerrSrc);
         = retry;
    }

    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
retry - If the exception is retriable or not
detailedMsg - The detailed message shown to the developer
    public PigException (String messageint errCodebyte errSrcboolean retryString detailedMsg) {
        this(messageerrCodeerrSrcretry);
         = detailedMsg;
    }
    
    
Create a new PigException with the specified message and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
retry - If the exception is retriable or not
detailedMsg - The detailed message shown to the developer
    public PigException (String messageint errCodebyte errSrcboolean retryString detailedMsgSourceLocation location) {
        this(messageerrCodeerrSrcretry);
         = detailedMsg;
         = location;
    }

    
Create a new PigException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
retry - If the exception is retriable or not
detailedMsg - The detailed message shown to the developer
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
    public PigException (String messageint errCodebyte errSrcboolean retryString detailedMsgThrowable cause) {
        super(messagecause);
         = errCode;
         = errSrc;
         = retry;
         = detailedMsg;
    }    
    
    
Create a new PigException with the specified message, error code, error source, retriable or not, detalied message for the developer and cause.

Parameters:
message - The error message (which is saved for later retrieval by the <link>Throwable.getMessage()</link> method) shown to the user
errCode - The error code shown to the user
errSrc - The error source
retry - If the exception is retriable or not
detailedMsg - The detailed message shown to the developer
cause - The cause (which is saved for later retrieval by the <link>Throwable.getCause()</link> method) indicating the source of this exception. A null value is permitted, and indicates that the cause is nonexistent or unknown.
location - The <link>SourceLocation</link> that generated this error.
    public PigException (String messageint errCodebyte errSrcboolean retryString detailedMsgThrowable causeSourceLocation location) {
        super(messagecause);
         = errCode;
         = errSrc;
         = retry;
         = detailedMsg;
         = location;
    }    
    
    
Checks if the exception is retriable.

Returns:
if the exception is retriable or not
    public boolean retriable() {
        return ;
    }

    
Set the retriable attribute of the exception

Parameters:
retry - true if retriable; false otherwise
    public void setRetriable(boolean retry) {
         = retry;
    }

    
Returns the error source of the exception. Can be more than one source.

Returns:
error sources represented as a byte
    public byte getErrorSource() {
        return ;
    }

    
Set the error source of the exception

Parameters:
src - byte representing the error sources
    public void setErrorSource(byte src) {
         = src;
    }

    
Returns the error code of the exception

Returns:
error code of the exception
    public int getErrorCode() {
        return ;
    }

    
Set the error code of the exception

Parameters:
code - error code
    public void setErrorCode(int code) {
         = code;
    }

    
Returns the detailed message used by developers for debugging

Returns:
detailed message
    public String getDetailedMessage() {
        return ;
    }

    
Set the detailed message of the exception

Parameters:
detailMsg - detailed message to be used by developers
    public void setDetailedMessage(String detailMsg) {
         = detailMsg;
    }
    
    
Check if this PigException is marked as the ones whose message is to be displayed to the user. This can be used to indicate if the corresponding error message is a good candidate for displaying to the end user, instead of drilling down the stack trace further.

Returns:
true if this pig exception is marked as appropriate to be displayed to the user
    public boolean getMarkedAsShowToUser() {
        return ;
    }
    
    
Mark this exception as a good candidate for showing its message to the pig user
    public void setMarkedAsShowToUser(boolean showToUser) {
         = showToUser;
    }
    
    
Return the location in the source that generated the exception.
    public SourceLocation getSourceLocation() {
        return ;
    }
    
    public void setSourceLocation(SourceLocation location) {
         = location;
    }
    
    
Returns a short description of this throwable. The result is the concatenation of:
  • the name of the class of this object
  • ": " (a colon and a space)
  • "ERROR " (the string ERROR followed by a a space)
  • the result of invoking this object's getErrorCode() method
  • ": " (a colon and a space)
  • the result of invoking getLocalizedMessage method
If getLocalizedMessage returns null, then just the class name is returned.

Returns:
a string representation of this throwable.
    @Override
    public String toString() {
        String s = getClass().getName();
        String message = getLocalizedMessage();
        return (message != null) ? (s + ": " + "ERROR " + getErrorCode() + ": " + message) : s;
    }
New to GrepCode? Check out our FAQ X