|
Hi, Consider i execute a method 'Method1' in C#. Once the execution goes into the method i check few condition and if any of them is false, then the execution of Method1 should be stopped. how can i do this, i.e can the execution of a method when certain...
Started by pragadheesh on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Edit: If you want to exit the method due to an error you can throw an exception like it with a try catch in the method calling your method, for instance:
void method1() { try { method2( 1 isOK = false; if(!isOK....
Question.
|
|
I have a deceptively simple scenario, and I want a simple solution, but it's not obvious which is "most correct" or "most Java".
Let's say I have a small authenticate(Client client) method in some class. The authentication could fail for a number of reasons...
Started by Draemon on
, 18 posts
by 18 people.
Answer Snippets (Read the full thread at stackoverflow):
Is this the only method where you have such a requirement? If not, just generate could just have the method return null....
Also, if the method that might fail is "low languages.
I don't like using arguments to collect messages.
Class.
|
|
Have a class with couple of integers and a pointer ,
class A { int a; int b; char* s; public: ... class ConstructA { A &a; public: ConstructA (A& ta) : a(ta) {} ... }; };
As seen ConstructA is responsible for constructing object A. I want to write a method...
Answer Snippets (Read the full thread at stackoverflow):
You may want to implement an additional method such as isOK, if you have an object that represents a file, then you could use isOK() to indicate that the file, and create an init() method....
At the point the exception is caught.
|
Ask your Facebook Friends
|
Hi,
I have a "Status" class in C#, used like this:
Status MyFunction() { if(...) // something bad return new Status(false, "Something went wrong") else return new Status(true, "OK"); }
You get the idea. All callers of MyFunction should check the returned...
Started by jan on
, 12 posts
by 11 people.
Answer Snippets (Read the full thread at stackoverflow):
Also,....
I'm fond of a bool return type and prefixing the method name with "Try", a la:
bool is this, I would leave it to the caller to check the return code, it is their responsability you just provide the means and interface.
Suggestion.
|
|
Suppose you are using the ternary operator, or the null coalescing operator, or nested if-else statements to choose assignment to an object. Now suppose that within the conditional statement, you have the evaluation of an expensive or volatile operation...
Answer Snippets (Read the full thread at stackoverflow):
For situations where the is OK ) ? temp : null;
Ok, so one could have a method
bool IsOk( Connection c ) { return ( c != null ) ? temp : ( temp = server....
In that you can alter the IsOk check at any stage and are entirely lazy.
|
|
Hello,
In the past 24 hours I've been trying to delete all objects on some of my S3 buckets. So far I haven't received any errors, but the objects are not deleted .
Any of these methods didn't worked out:
delete_all_objects() delete_all_object_versions...
Started by juangiordana on
, 11 posts
by 2 people.
Answer Snippets (Read the full thread at amazon):
If there is an error message, it will be in $response->(); $response = $s3->delete_bucket(AWS_S3_BUCKET, TRUE); var_dump($response->isOK()); exit; */ $objects.
To do instead is check $response->isOK().
|
|
Given the following code (that doesn't work):
while True: #snip: print out current state while True: ok = get_input("Is this ok? (y/n)") if ok == "y" or ok == "Y": break 2 #this doesn't work :( if ok == "n" or ok == "N": break #do more processing with...
Started by Matthew Scharley on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
You could set a variable in the inner loop, and check it in the outer loop immediately after the inner loop exits, breaking....
Not done: isok= False while not (done or isok): ok = get_input("Is this ok? (y/n)") if ok in ("y", "Y like that.
|
|
When is it right for a constructor to throw an exception? (Or in the case of Objective C: when is it right for an init'er to return nil?)
It seems to me that a constructor should fail -- and thus refuse to create an object -- if the object isn't complete...
Started by markrlindsey on
, 22 posts
by 22 people.
Answer Snippets (Read the full thread at stackoverflow):
The method can throw if ....
Because of all something during construction, make the constructor private and define a public static factory method.
A Init() or Setup() method if you want to perform some more complicated object setup.
|
|
Enum SQLErrorCode{ OK = 0, PARTIAL_OK = 1, SOMEWHAT_OK = 2, NOT_OK = 3, };
Code 1:
int error = getErrorCode(); if((error == SQLErrorCode.PARTIAL_OK) || (error == SQLErrorCode.SOMEWHAT_OK) || (error == SQLErrorCode.NOT_OK) || (error < 0)) callFunction...
Started by Devil Jin on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Error code is:
bool isOK(int code) { return code == SQLErrorCode.OK; }
and your code could become:
if (isOk(getErrorCode())) { callFunction2; } else { callFunction1; }
Not that it matters much.
|
|
There appears to be a memory leak within the PHP SDK. We picked this up after we tried to create a Daemon which polls a queue and processes any actionable items.
while ( true ) {
$sqs = new AmazonSQS()
$size = $sqs->get_queue_size( 'some_queue_url'...
Started by al3xdm on
, 19 posts
by 5 people.
Answer Snippets (Read the full thread at amazon):
Can you check your php.ini file and look' ); if ($response->isOK()) { $queue_url = $response->body->QueueUrl(0); } else { print_r); if ($response->isOK()....
As we're doing some PHP 5.4 alpha testing at the moment anyway .
|