001 /**
002 * Copyright (C) 2009-2013 Barchart, Inc. <http://www.barchart.com/>
003 *
004 * All rights reserved. Licensed under the OSI BSD License.
005 *
006 * http://www.opensource.org/licenses/bsd-license.php
007 */
008 package com.barchart.udt;
009
010 import java.net.SocketException;
011
012 import com.barchart.udt.anno.Native;
013
014 /**
015 * The Class ExceptionUDT. Wraps all native UDT exceptions and more.
016 */
017 @SuppressWarnings("serial")
018 public class ExceptionUDT extends SocketException {
019
020 /**
021 * The error udt. Keeps error description for this exception. Use this enum
022 * in switch/case to fine tune exception processing.
023 */
024 @Native
025 private final ErrorUDT errorUDT;
026
027 public ErrorUDT getError() {
028 return errorUDT;
029 }
030
031 /**
032 * The socket id. Keeps socketID of the socket that produced this exception.
033 * Can possibly contain '0' when particular method can not determine
034 * {@link #socketID} that produced the exception.
035 */
036 @Native
037 private final int socketID;
038
039 public int getSocketID() {
040 return socketID;
041 }
042
043 /**
044 * Instantiates a new exception udt for native UDT::Exception. This
045 * exception is generated in the underlying UDT method.
046 *
047 * @param socketID
048 * the socket id
049 * @param errorCode
050 * the error code
051 * @param comment
052 * the comment
053 */
054 @Native
055 protected ExceptionUDT(final int socketID, final int errorCode,
056 final String comment) {
057 super(ErrorUDT.descriptionFrom(socketID, errorCode, comment));
058 errorUDT = ErrorUDT.errorFrom(errorCode);
059 this.socketID = socketID;
060 }
061
062 /**
063 * Instantiates a new exception udt for synthetic JNI wrapper exception.
064 * This exception is generated in the JNI glue code itself.
065 *
066 * @param socketID
067 * the socket id
068 * @param error
069 * the error
070 * @param comment
071 * the comment
072 */
073 @Native
074 protected ExceptionUDT(final int socketID, final ErrorUDT error,
075 final String comment) {
076 super(ErrorUDT.descriptionFrom(socketID, error.getCode(), comment));
077 errorUDT = error;
078 this.socketID = socketID;
079 }
080
081 }