source: branches/0.17.x/abcl/src/org/armedbear/lisp/StreamError.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1/*
2 * StreamError.java
3 *
4 * Copyright (C) 2002-2005 Peter Graves
5 * $Id: StreamError.java 12254 2009-11-06 20:07:54Z ehuelsmann $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public class StreamError extends LispError
37{
38    private final Throwable cause;
39
40    protected StreamError(LispClass cls)
41    {
42        super(cls);
43        cause = null;
44    }
45
46    public StreamError(String message)
47    {
48        super(StandardClass.STREAM_ERROR);
49        setFormatControl(message);
50        setFormatArguments(NIL);
51        setStream(NIL);
52        cause = null;
53    }
54
55    public StreamError(Stream stream)
56    {
57        super(StandardClass.STREAM_ERROR);
58        setStream(stream != null ? stream : NIL);
59        cause = null;
60    }
61
62    public StreamError(String message, Stream stream)
63    {
64        super(StandardClass.STREAM_ERROR);
65        setFormatControl(message);
66        setFormatArguments(NIL);
67        setStream(stream != null ? stream : NIL);
68        cause = null;
69    }
70
71    public StreamError(LispObject initArgs)
72    {
73        super(StandardClass.STREAM_ERROR);
74        initialize(initArgs);
75        cause = null;
76    }
77
78    @Override
79    protected void initialize(LispObject initArgs)
80    {
81        super.initialize(initArgs);
82        while (initArgs != NIL) {
83            LispObject first = initArgs.car();
84            initArgs = initArgs.cdr();
85            if (first == Keyword.STREAM) {
86                setStream(initArgs.car());
87                break;
88            }
89            initArgs = initArgs.cdr();
90        }
91    }
92
93    public StreamError(Stream stream, String message)
94    {
95        super(StandardClass.STREAM_ERROR);
96        setFormatControl(message);
97        setFormatArguments(NIL);
98        setStream(stream != null ? stream : NIL);
99        cause = null;
100    }
101
102    public StreamError(Stream stream, Throwable cause)
103    {
104        super(StandardClass.STREAM_ERROR);
105        setStream(stream != null ? stream : NIL);
106        this.cause = cause;
107    }
108
109    public final LispObject getStream()
110    {
111        return getInstanceSlotValue(Symbol.STREAM);
112    }
113
114    protected final void setStream(LispObject stream)
115    {
116        setInstanceSlotValue(Symbol.STREAM, stream);
117    }
118
119    @Override
120    public LispObject typeOf()
121    {
122        return Symbol.STREAM_ERROR;
123    }
124
125    @Override
126    public LispObject classOf()
127    {
128        return StandardClass.STREAM_ERROR;
129    }
130
131    @Override
132    public LispObject typep(LispObject type)
133    {
134        if (type == Symbol.STREAM_ERROR)
135            return T;
136        if (type == StandardClass.STREAM_ERROR)
137            return T;
138        return super.typep(type);
139    }
140
141    @Override
142    public String getMessage()
143    {
144        if (cause != null) {
145            String s = cause.getMessage();
146            if (s != null && s.length() > 0)
147                return s;
148        }
149        return null;
150    }
151
152    // ### stream-error-stream
153    private static final Primitive STREAM_ERROR_STREAM =
154        new Primitive("stream-error-stream", "condition")
155    {
156        @Override
157        public LispObject execute(LispObject arg)
158        {
159            if (arg instanceof StreamError) 
160                return ((StreamError)arg).getStream();               
161            return error(new TypeError(arg, Symbol.STREAM_ERROR));
162        }
163    };
164}
Note: See TracBrowser for help on using the repository browser.