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 '}'
Related
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" } } }
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 have the simplest of scripts in LiveCode attempting to parse a small chunk of JSON using the MergJSON library.
This is doubtless something stupid I'm doing as it's been a long day, but I just can't get the JSON parsed into a LiveCode array:
LC Script in a button called 'Connect'
function JSONToArray pJSON
local tArray,tKeys
repeat for each line tKey in mergJSONDecode(pJSON,"tArray")
put JSONToArray(tArray[tKey]) into tArray[tKey]
end repeat
return tArray
end JSONToArray
on mouseUp
put field "MyJSON" into pJSON
answer JSONToArray()
end mouseUp
My JSON
{
"firstname":"Mary",
"lastname":"Smith",
}
The Error:
Button "Connect": execution error at line n/a (External handler: exception) near "could not decode JSON: unexpected token near end of file"
Suggestions would be most welcome....
Thanks,
Steve
Mark B might have it but the other thing could be that you're not passing the parameter to JSONToArray...
put JSONToArray(pJSON) into tArray
put tArray["firstname"]
{
"firstname":"Mary",
"lastname":"Smith", <---dangling comma
}
My node server dies when it is unable to parse JSON in the following line:
var json = JSON.parse(message);
I read this thread on how to catch exceptions in node, but I am still not sure what is the proper way to wrap a try and catch block around this statement. My goal is to catch the exception and log an error to the console, and of course keep the server alive. Thank you.
It's all good! :-)
JSON.parse runs synchronous and does not know anything about an err parameter as is often used in Node.js. Hence, you have very simple behavior: If JSON parsing is fine, JSON.parse returns an object; if not, it throws an exception that you can catch with try / catch, just like this:
webSocket.on('message', function (message) {
var messageObject;
try {
messageObject = JSON.parse(message);
} catch (e) {
return console.error(e);
}
// At this point, messageObject contains your parsed message as an object.
}
That's it! :-)