Jscript try & catch get error message - try-catch

As the title says im trying to get a error exception :
try{
objshell.run("testfile.exe");
}catch(ex){
WScript.echo(ex.message);
}
the code above just returns an empty message box if file testfile.exe does not exist.
is there any way to read the error reason? (example : file does not exists)

There is a distinction between JScript and JScript .NET. If you are using Microsoft's implementation, then you could additionally print out ex.description, ex.name and ex.number.
In your code, just use:
WScript.echo(ex);

Related

Suppress messages from underlying C-function in R

In a script I often call the function Rcplex(), which prints "CPLEX environment opened" and "Closed CPLEX environment" to the console. Since the function is called rather frequently, it prints this very often, which is quite annoying. Is there a way to suppress this? I tried sink(), suppressWarnings/Messages or invisible(catch.output()) but none of these did the trick. I proceeded to check the code of Rcplex() and found where the printing to the console happens. Rcplex() calls an underlying C-function (Rcplex.c). In the code of rcplex.c I located the commands which cause the printing:
REprintf("CPLEX environment opened\n");
REprintf("Closed CPLEX environment\n");
Is there a way to capture the output from REprintf() so that it does not get printed to the R-console? One way would obviously be to mess around with the Rcplex.c file and delete the corresponding lines. However, this would not be a very clean solution, which is why I'm asking for another way to capture the output from C-functions.
You had problems using sink() and capture.output() normally because sink() does not redirect output from REprintf, as we see in comments from the source code for REprintf:
/* =========
* Printing:
* =========
*
* All printing in R is done via the functions Rprintf and REprintf
* or their (v) versions Rvprintf and REvprintf.
* These routines work exactly like (v)printf(3). Rprintf writes to
* ``standard output''. It is redirected by the sink() function,
* and is suitable for ordinary output. REprintf writes to
* ``standard error'' and is useful for error messages and warnings.
* It is not redirected by sink().
However, we can use type = "message" to deal with this; from help("capture.output"):
Messages sent to stderr() (including those from message, warning and
stop) are captured by type = "message". Note that this can be "unsafe" and should only be used with care.
First I make a C++ function with the same behavior you're dealing with:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector example_function(NumericVector x) {
REprintf("CPLEX environment opened\n");
REprintf("Closed CPLEX environment\n");
// As mentioned by Dirk Eddelbuettel in the comments,
// Rcpp::Rcerr goes into the same REprintf() stream:
Rcerr << "Some more stuff\n";
return x;
}
If I call it from R normally, I get:
example_function(42)
CPLEX environment opened
Closed CPLEX environment
Some more stuff
[1] 42
However, I could instead do this:
invisible(capture.output(example_function(42), type = "message"))
[1] 42
And while the output is is printed to the console, the message is not.
Warning
I would be remiss if I didn't mention the warning from the help file I quoted above:
Note that this can be "unsafe" and should only be used with care.
The reason is that this will eliminate all output from actual errors as well. Consider the following:
> log("A")
Error in log("A") : non-numeric argument to mathematical function
> invisible(capture.output(log("A"), type = "message"))
>
You may or may not want to therefore send the captured output to a text file in case you have to diagnose something that went wrong. For example:
invisible(capture.output(log("A"), type = "message", file = "example.txt"))
Then I don't have to see the message in the console, but if I need to check example.txt afterward, the message is there:
Error in log("A") : non-numeric argument to mathematical function

why this error appears "all scheduled cores encountered errors in user code" is it related to core processor of servers?

We are analyzing sequencing data while filtering and trimming fastq files encountered following error. Is the following error due to unavailability of core for processing commands?
Error in colnames<-(*tmp*, value = c("cs103_R1_dada.fastq", "cs110_R1_dada.fastq", : attempt to set 'colnames' on an object with less than two dimensions In addition: Warning message: In mclapply(seq_len(n), do_one, mc.preschedule = mc.preschedule, : all scheduled cores encountered errors in user code >
As pengchy suggested there may be something wrong with function.
try the same call by using lapply and error message will be more informative.
To clarify on what #f2003596 and #HelloWorld said: This just means that a crash occurred within the function you called, i.e. while it was executing that function. But this does not necessarily mean that your function is incorrect. For example, you get the same error when a variable has not been found.
That would mean your R function has a crash.
Note: If you include an unexpected argument in mclapply you also can get this error message. I put mC.cores instead of mc.cores by mistake and I got it.

how can i open my .sgrd file?

I need to open my system monitor in the QTCreator, but when I try to do it I obtain the following error message:
/home/arakul/sysmon.sgrd: 2: /home/arakul/sysmon.sgrd: Syntax error: newline unexpected
I am trying to open the system monitor by using the following command:
execlp("/home/arakul/sysmon.sgrd","",NULL);
Sorry for my stupid question. I must use command ksysguard with parametrs.
system("ksysguard --desktopfile sysmon.sgrd");

Autohotkey soundplay does not work with every wav

I have noticed that SoundPlay does not work with every wav I use. I can play the files normally, but when I use SoundPlay, some of them won't play and throw an error. I tried to get more details about the error but the exception does not show anything.
In the sample code the first file does not play and throws an exception but 'e' is empty. If I comment it out the other two plays without any problem. Any ideas?
try
{
SoundPlay, c:\Alarm Files\La Cucaracha - Intro.wav, Wait ; THIS DOES NOT PLAY
SoundPlay, c:\Alarm Files\Marimba.wav, Wait ; PLAYS WITH NO ERROR
SoundPlay, c:\Alarm Files\Train Crossing.wav, Wait ; PLAYS WITH NO ERROR
}
catch e
{
MsgBox, An exception was thrown!`nDetails: %e%
}
return
Per the documentation
Known limitation: If the WAIT parameter is omitted, the OS might consider the playing file to be "in use" until the script closes or until another file is played (even a nonexistent file).
SoundPlay, FILEPATH, Wait
As an obscure alternative you could try running the audio via a DLL call.
FilePath := "c:\Alarm Files\La Cucaracha - Intro.wav"
DllCall("winmm.dll\PlaySound", AStr, FilePath, uint, 0, uint, 0)

Erlang file:consult and system_limit error

I use file:consult function to read data from config file of my application. But some times i got error: {badmatch,{error,system_limit}} How can i avoid this?
I read about ERL_MAX_PORTS, but i haven't this variable:
echo $ERL_MAX_PORTS
i got empty string. How i can correctly set ERL_MAX_PORTS or can i find other methods to avoid this error?
Thank you

Resources