Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have something like this
isLastPermutation (h:t)=
catch (nextPermutation (h:t)) (\e-> return True)
return False
In some cases nextPermutation throws an exception and I want my function isLastPermutation to return true if nextPermutation throws exception otherwise false.
Don't use exceptions for flow-control in otherwise pure Haskell. Use Maybe or Either.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I've got this example:
try {
images = this.getFinderFiles(path);
} catch (DirectoryNotFoundException exception) {
return [];
}
There is something wrong with this code?
I would recommend not to use exception handling for expected error situations. Exception handling takes time, stack unwinding has to be done.
In your case, if you usually can expect that 'path' usually exists and therefore the method can return a decent result - so you do not expect that 'this.getFinderFiles' fails - then it is fine to use exceptions here. But otherwise test the path for existence first before calling 'getFinderFiles'. That should be faster and for my taste more readable.
Btw. can you check the existence of 'path' within 'getFinderFiles' and eventually return '[]' already there?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I've got an assignment that is due tomorrow..
I don't want the entire solution, there's just a part of the program that i dont understand.
It's highlighted in the image below:
(I dont know what "save the values into the parameters of a method" means)
As you can see the type of the parameters is double& which means you are storing the values within the arguments you are sending. e.g, if you have 3 doubles a,b & c, when you call getAll(a,b,c) the result should be stored in them.
You can find more detailed explanation about &(reference) operator in
What does '&' do in a C++ declaration? .
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
guys I have this code which is written in Json as it is supposed to generate a document with repeated objects _id and items
I have used repeat function and passed a list to it with these objects , also i do not have clear understanding about what objectid do
'repeat(21, 0)': [ {_id :objectId()}
, items : items()} ]
but it is giving me this error SyntaxError: Unexpected token :
I am using this site https://next.json-generator.com
solved guys , you can find the code below
[
{
'repeat(21, 0)': {
_id: '{{objectId()}}',
items: '{{company().toUpperCase()}}',
}
}
]
it is a list with an object which contain a function repeating its containing objects
, please correct me if i am wrong or give more clarification.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm a little confused about this.
I have a server returning a JSON string that represents an array of custom objects that I have defined. I need to perform some tests and check if each element of this array can be correctly cast/parsed to my object.
What is the correct way to do this?
I thought about creating a new Object and passing my JSON.parse(element) result to the constructor, but then how do I check if it was correctly created? Does it throw an exception?
Here is the simple way to check it:
checkJsonObject(string) {
try {
JSON.parse(string);
} catch (e) {
return false;
}
return true;
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Should we use assertEquals or assertTrue for comparing primitive types specifically ints?
Is there a preference, if so why ? I'd like to know the pros and cons of each approach.
assertEquals() gives a useful default error message on failure, like "expected X but got Y", but assertTrue() can't. Use the more specific applicable method here, which is assertEquals().
assertEquals() is to test the equality of your expected value with the returning value. Whereas assertTrue() is to check for a condition. Having said that, you can also say
If you have a condition like.
String x = "abc";
String y = "abc";
assertEquals(x, y);
You can also change it to
assertTrue(x.equals(y));
It is just another way of asserting what you expect.