-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy patherror_handling.php
63 lines (51 loc) · 1.51 KB
/
error_handling.php
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
<?php
require __DIR__."/../src/autoload.php";
/**
* To run example create config.php
* defining following constants
*
* define('RSERVE_HOST', 'localhost'); // Host to use
*
*/
require __DIR__.'/config.php';
use Sentiweb\Rserve\Connection;
use Sentiweb\Rserve\Parser\NativeArray;
use Sentiweb\Rserve\Exception as Rserve_Exception;
use Sentiweb\Rserve\Parser\REXP;
use Sentiweb\Rserve\Parser\Sentiweb\Rserve\Parser;
$cnx = new Connection(RSERVE_HOST);
// Using NativeArray
// Run an error
try {
$command = 'seq(1,10, by=NA)';
$command = 'r= try({'.$command.'}, silent=T); if( inherits(r,"try-error")) { r = structure(list("try-error"=TRUE, message=unclass(r))) }; r';
$r = $cnx->evalString($command);
//var_dump($r);
} catch(Rserve_Exception $e) {
var_dump($e);
}
echo "NativeArray\n";
$parser = new NativeArray(array('wrapper'=>true));
try {
$command = 'seq(1,10, by=NA)';
$command = 'r= try({'.$command.'}, silent=T); if( inherits(r,"try-error")) { r = structure(list(message=unclass(r)), class="try-error") }; r';
$r = $cnx->evalString($command, $parser);
var_dump($r);
} catch(Rserve_Exception $e) {
var_dump($e);
}
echo "REXP\n";
$parser = new REXP();
try {
$command = 'seq(1,10, by=NA)';
$command = 'try({'.$command.'}, silent=T)';
$r = $cnx->evalString($command, $parser);
$class = $r->getAttribute('class');
if($class) {
$class = $class->getValues();
}
//var_dump($class);
//var_dump($r);
} catch(Rserve_Exception $e) {
var_dump($e);
}