]> gerrit.simantics Code Review - simantics/r.git/blob - org.simantics.r.scl/src/org/rosuda/REngine/REXPMismatchException.java
5b749a27b6efa5cfa91158461edb1a97a6495c6e
[simantics/r.git] / org.simantics.r.scl / src / org / rosuda / REngine / REXPMismatchException.java
1 // REngine - generic Java/R API
2 //
3 // Copyright (C) 2007,2008 Simon Urbanek
4 // --- for licensing information see LICENSE file in the distribution ---
5 //
6 //  REXPMismatch.java
7 //
8 //  Created by Simon Urbanek on 2007/05/03
9 //
10 //  $Id: REngineException.java 2555 2006-06-21 20:36:42Z urbaneks $
11 //
12
13 package org.rosuda.REngine;
14
15 /** This exception is thrown whenever the operation requested is not supported by the given R object type, e.g. using <tt>asStrings</tt> on an S4 object. Most {@link REXP} methods throw this exception. Previous R/Java interfaces were silently returning <code>null</code> in those cases, but using exceptions helps to write more robust code. */
16 public class REXPMismatchException extends Exception {
17         REXP sender;
18         String access;
19         
20         /** primary constructor. The exception message will be formed as "attempt to access &lt;REXP-class&gt; as &lt;access-string&gt;"
21          * @param sender R object that triggered this exception (cannot be <code>null</code>!)
22          * @param access assumed type of the access that was requested. It should be a simple name of the assumed type (e.g. <tt>"vector"</tt>). The type name can be based on R semantics beyond basic types reflected by REXP classes. In cases where certain assertions were not satisfied, the string should be of the form <tt>"type (assertion)"</tt> (e.g. <tt>"data frame (must have dim>0)"</tt>). */
23     public REXPMismatchException(REXP sender, String access) {
24         super("attempt to access "+sender.getClass().getName()+" as "+access);
25                 this.sender = sender;
26                 this.access = access;
27     }
28         
29         /** retrieve the exception sender/origin
30          * @return REXP object that triggered the exception */
31         public REXP getSender() {
32                 return sender;
33         }
34         
35         /** get the assumed access type that was violated by the sender.
36          * @return string describing the access type. See {@link #REXPMismatchException} for details. */
37         public String getAccess() {
38                 return access;
39         }
40 }