I am running analysis on about 10000 lines of numbers, and some of the lines give me errors: "Use of uninitialized value of type Any in numeric context". I am trying to catch this error to see which lines are causing the problem. However, the X::TypeCheck, and other X::* classes don't seem to do effective catching autovivification of Nil or Any. E.g.:
try { say Any + 1; CATCH { default { say "oh-no"; } }; }
still gives me answer of "1" after printing out the warning message and does not say "oh-no" that I want.
What is the proper way to catch these non-fatal autovivification errors? And by the way, is there a nuclear-powered perl6 debugger?
Thank you very much !!!
lisprog
Use quietly and CONTROL instead of try and CATCH:
quietly { say Any + 1; CONTROL { default { say "oh-no" } } }
Related
Looks like my node server dies in parseJSON.
Looked at the logs and the last message was "before parse" and it never printed "after parse". What's strange is that I wrapped JSON.pars with try-catch so I am not sure how it caused the server crashed. Any thoughts?
logger.print("before parse")
parseJSON(data)
logger.print("after parse")
and I have pareJSON catch exception.
function parseJSON(str) {
try {
var result = JSON.parse(str);
return result;
} catch (err) {
return null
}
}
If your code crashes in parseJSON then I would try:
try {
logger.print("before parse")
parseJSON(data)
logger.print("after parse")
} catch (e) {
console.log(e);
}
It is strange because your function should catch the exception but this would show what happens. I would also add:
console.log(data.length);
to see the size of the data.
Also I wrote a module tryjson that parses JSON without throwing exceptions. You can try using it but if your function crashes then maybe my module would not handle it either. Though I'd love to know what actually happens.
I have below code : Which is iterating the arrayList till end even though I don't want it. I don't know how to break it as xtend does not have break statement. Provided I can't convert the same to a while loop, is there any alternative way in xtend similar to break statement in java?
arrayList.forEach [ listElement | if (statusFlag){
if(monitor.canceled){
statusFlag = Status.CANCEL_STATUS
return
}
else{
//do some stuff with listElement
}
}]
You can try something like that
arrayList.takeWhile[!monitor.cancelled].forEach[ ... do stuff ...]
if ( monitor.cancelled ) { statusFlag = Status.CANCEL_STATUS }
takeWhile is executed lazily, so it should work as expected and break at correct moment (memory visibility allowing, I hope monitor.cancelled is volatile).
Not sure how status flag comes into picture here, you might need to add check for it in one or both closures as well.
You are right, break and continue is not supported by Xtend.
Because it seems that you would like to 'break' based on an external condition (so you can't use e.g. filtering) I think it's not a bad option to throw an exception.
Pseudo code:
try {
arrayList.forEach[
if (monitor.canceled) {
throw new InterruptedException()
}
else {
// Continue processing
}
]
}
catch (InterruptedException e) {
// Handle
}
You are right, break and continue is not supported by Xtend.
Move break specific functionality to java and use that in xtend.
I would like your help here, this is my actionscript3 code.
Everytime I compile I get error.
Line 1537 1073: Syntax error: expecting a catch or a finally clause.
This is the code
{
try
{
}
_loc_3.badge.gotoAndStop(param1.split(":")[2]);
}
And the second error
{
try
{
}
_loc_3.badge.gotoAndStop(param1.split(":")[2]);
}
The second error says:
Line 1537 1084: Syntax error: expecting rightbrace before semicolon.
Could anyone help me here, thanks in advance.
UPDATE: After I add a right brace before the semicolon it gives more errors.
The first error is really explicit, you need a catch block. The empty try block is useless.
The syntax found on a website.
try {
//Your code
}
catch(e:Error) { // Error handling
trace("Error found: " + e);
}
//Optional
finally {
// Closing connection for example.
}
Website reference in french
A try cannot be used without a catch. the idea there is lets try this piece of code and if we run into any problems stop and execute the content of whatever is in the catch. the finally is used for executing code that you want to run regardless of whether the try or catch gets executed.
in the first error:
you are just missing a catch. also maybe include some code into the try statement, otherwise its pointless to use.
example:
try
{
//try to feed my dog
feedDog();
}
//if some error occurs in feedDog() then the catch will be called
//if you want to catch specific exceptions
//then specify its type instead of Exception
catch (Exception e)
{
trace("unable to feed dog");
}
//this will execute whether the dog was fed successfully or not
finally
{
trace("leave");
}
with the second error: you are probably missing a '}' somewhere in that function. Indent your code so that these will become clearly visible to you and you can match every '{' with its corresponding '}'
I have one object (jar), which contains this (by console.log):
{ _jar: { store: { idx: { localhost: { '/': { PHPSESSID: Cookie="PHPSESSID=pe1952pk023e7b6d7t9am3kse0; Path=/; hostOnly=true; aAge=18ms; cAge=97ms" } } } } } }
I'm trying to store it to MongoDB instance which is ok, but after loading it from there, it's kind of malformed. This simulates it:
console.log(JSON.parse(JSON.stringify(jar)));
The above outputs this:
{ _jar: { store: { idx: [Object] } } }
So all of the sudden 'localhost' part got vanished into 'Object'? How to prevent this?
console.log doc says:
If formatting elements are not found in the first string then
util.inspect is used on each argument.
util.inspect doc says:
Return a string representation of object, which is useful for
debugging.
[...]
depth - tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects.
Defaults to 2. To make it recurse indefinitely pass null.
That is, console.log(jar) prints only the first two levels, _jar and store, and the fields of store are printed in short format. That's why the content of store.idx is printed as [Object]. To print every level, type util.inspect(jar, { depth: null }).
That console.log formatting, not a JSON.parse problem.
console.log(jar) will give you the same output.
I've got this JSON file that I'm trying to parse the second level off. But it seems to fail.
{
"error":false,
"accessToken":"xxx",
"accountId":"xxx",
"account":[
{
"error":false,
"id":"2",,
"username":"Username"
}]
}
Here's the Ionic code
return $http.post(SERVER.apiUrl + SERVER.apiLogin,
{username: "username",password: "password"})
.success(function(data){
o.setSession(data.accountId, data.accessToken, data.account[0]["username"]);
});
Error
TypeError: Cannot read property '0' of undefined
at services.js:103
at ionic.bundle.js:17151
at processQueue (ionic.bundle.js:20962)
at ionic.bundle.js:20978
at Scope.$eval (ionic.bundle.js:22178)
at Scope.$digest (ionic.bundle.js:21994)
at Scope.$apply (ionic.bundle.js:22282)
at done (ionic.bundle.js:17439)
at completeRequest (ionic.bundle.js:17629)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:17570)
i have also tried with
data.account.username
and
data.account[0].username
Can anybody give a quick advice?
Best regards
do not understand why it does not work for you, I tried it and does not give me problems.
Although at least here, you put two commas after ID
data.account[0]["username"] Is Ok
{
"error":false,
"accessToken":"xxx",
"accountId":"xxx",
"account":[
{
"error":false,
"id":"2",, <-- ERROR
"username":"Username"
}]
}