1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
* Copyright (c) 2009 Samit Basu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "Array.hpp"
#include "Interpreter.hpp"
//!
//@Module LASTERR Retrieve Last Error Message
//@@Section FLOW
//@@Usage
//Either returns or sets the last error message. The
//general syntax for its use is either
//@[
// msg = lasterr
//@]
//which returns the last error message that occured, or
//@[
// lasterr(msg)
//@]
//which sets the contents of the last error message.
//@@Example
//Here is an example of using the @|error| function to
//set the last error, and then retrieving it using
//lasterr.
//@<
//try; error('Test error message'); catch; end;
//lasterr
//@>
//Or equivalently, using the second form:
//@<
//lasterr('Test message');
//lasterr
//@>
//@@Tests
//@{ test_lasterr1.m
//function test_val = test_lasterr1
// try
// error('Hulabaloo');
// catch;
// end;
// test_val = strcmp(lasterr,'Hulabaloo');
//@}
//@@Signature
//sfunction lasterr LasterrFunction
//inputs msg
//outputs msg
//!
ArrayVector LasterrFunction(int nargout, const ArrayVector& arg,
Interpreter* eval) {
if (arg.size() == 0)
return ArrayVector(Array(eval->getLastErrorString()));
eval->setLastErrorString(arg[0].asString());
return ArrayVector();
}
//!
//@Module ERRORCOUNT Retrieve the Error Counter for the Interpreter
//@@Section FREEMAT
//@@Usage
//This routine retrieves the internal counter for the interpreter,
//and resets it to zero. The general syntax for its use is
//@[
// count = errorcount
//@]
//@@Signature
//sfunction errorcount ErrorCountFunction
//inputs none
//outputs count
//!
ArrayVector ErrorCountFunction(int nargout, const ArrayVector& arg,
Interpreter* eval) {
return ArrayVector(Array(double(eval->getErrorCount())));
}
//!
//@Module WARNING Emits a Warning Message
//@@Section FLOW
//@@Usage
//The @|warning| function causes a warning message to be
//sent to the user. The general syntax for its use is
//@[
// warning(s)
//@]
//where @|s| is the string message containing the warning.
//@@Signature
//sfunction warning WarningFunction
//inputs msg
//outputs none
//!
ArrayVector WarningFunction(int nargout, const ArrayVector& arg, Interpreter* eval) {
if (arg.size() == 0)
throw Exception("Not enough inputs to warning function");
if (!(arg[0].isString()))
throw Exception("Input to error function must be a string");
eval->warningMessage(arg[0].asString());
return ArrayVector();
}
//!
//@Module ERROR Causes an Error Condition Raised
//@@Section FLOW
//@@Usage
//The @|error| function causes an error condition (exception
//to be raised). The general syntax for its use is
//@[
// error(s),
//@]
//where @|s| is the string message describing the error. The
//@|error| function is usually used in conjunction with @|try|
//and @|catch| to provide error handling. If the string @|s|,
//then (to conform to the MATLAB API), @|error| does nothing.
//@@Example
//Here is a simple example of an @|error| being issued by a function
//@|evenoddtest|:
//@{ evenoddtest.m
//function evenoddtest(n)
// if (n==0)
// error('zero is neither even nor odd');
// elseif ( n ~= fix(n) )
// error('expecting integer argument');
// end;
// if (n==int32(n/2)*2)
// printf('%d is even\n',n);
// else
// printf('%d is odd\n',n);
// end
//@}
//The normal command line prompt @|-->| simply prints the error
//that occured.
//@<2
//evenoddtest(4)
//evenoddtest(5)
//evenoddtest(0)
//evenoddtest(pi)
//@>
//@@Tests
//@{ test_error1.m
//function test_val = test_error1
// test_val = false;
// try
// error('test')
// catch
// test_val = true;
// end
//@}
//@@Signature
//function error ErrorFunction
//inputs string
//outputs none
//!
ArrayVector ErrorFunction(int nargout, const ArrayVector& arg) {
if (arg.size() == 0)
return ArrayVector();
QString etxt(arg[0].asString());
if (!etxt.isEmpty())
throw Exception(etxt);
return ArrayVector();
}
|