|
I am implementing an interface which defines a method that can throw an exception if the parameters are not valid. What constitutes valid parameters depends on the implementing class. The interface also defines an isValid() method which can be used to...
Started by Grundlefleck on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
If your object is mutable and has setters, perhaps you could move the check { private boolean....
The logic for testing validity once, but either return false or throw an exception as per the throwIfInvalid implementation for isValid().
|
|
I know most people think that as a bad practice but when you are trying to make your class public interface only work with references, keeping pointers inside and only when necessary, I think there is no way to return something telling that the value ...
Started by Augusto Radtke on
, 12 posts
by 12 people.
Answer Snippets (Read the full thread at stackoverflow):
&() const { if (!_value) throw Exception("that is a problem and you made a mistake somewhere."); else return it:
// 'reference' style, check before use if (Accessor<type> value = list.get(key)) { type &v = value, skip....
|
|
I've been utilizing NHibernate 2.0.1.4000 on all current .NET 3.5 SP1 projects and have had no problems with any other queries (utilizing either the Query or Criteria APIs), until some new business logic dictated the necessity of a new query in this particular...
Started by Scott Wade on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Not as performant, but until I figure it out, it'... .
For the applicable table, the actual SQL my criteria with restrictions is generating, causes the exception first restriction and handle the IsNull check in the code instead of the query.
|
Ask your Facebook Friends
|
According to the .NET Framework General Reference: Error Raising and Handling Guidelines exceptions should not be thrown during 'normal' operations. Is invalid user input to a web form, say the user enters a duplicate name, considered normal? !! IMPORTANT...
Started by Paul on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
In all other....
If you are explicitly validating to throw.
So, throwing an exception would that type of exception that would stop your application completely.
Should always be managed by the method taking in the data .
|
|
There are already lots of questions on SO about exceptions, but I can't find one that answers my question. Feel free to point me in the direction of another question if I've missed it.
My question is quite simple: how do other (C#) developers go about...
Started by Paul Suart on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
If you check....
Cwalina has a good post on this see chapter "1.1.1 Choosing the Right Type of Exception to Throw"
PS), the message that you put in the exception is more useful than the type of the exception.
|
|
If I've got the following, really for any string where you check IsNullOrEmpty and it turns up empty, what kind of exception type should one throw, and it's not a argument to a method ?
I always have a hard time picking exception types because there are...
Answer Snippets (Read the full thread at stackoverflow):
I think you should throw an ArgumentNullException if the value is null and an ArgumentException....
Picking from of the list below when throwing a new exception (as opposed to simply doing a throw in for an argument.
|
|
Using .NET 3.5 and C# 3.0,
IList list = new List<bool?>(); list.Add(null);
This throws an ArgumentException, which just feels wrong.
List<bool?> list = new List<bool?>(); list.Add(null);
Works perfectly.
Is this a bug in Microsoft's ...
Started by ckknight on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
checking before trying to add the item to the internal storage -- and it gets this type checking wrong when you access the List<bool?> through its weak-typed IList implementation, it does some type implementation....
|
|
I see a lot of code written where an exception is thrown if a parameter is not in the right form, or whatever. Basically "throw new ...".
What is the benefit of this? The exception can be avoided by checking the parameters (Eg if null, write message back...
Started by dotnetdev on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
So throwing an exception to throw an ....
Throwing an exception:
makes it clear to other programmers that the situation is exceptional allows, how that error is handled is down to the code that is making the call.
|
|
When should I create a checked exception, and when should I make a runtime exception?
For example, suppose I created the following class:
public class Account { private float balance; /* ... constructor, getter, and other fields and methods */ public ...
Started by Hosam Aly on
, 14 posts
by 14 people.
Answer Snippets (Read the full thread at stackoverflow):
Or you can follow ....
In that case, you have all.
But the use of the method should, isn't good anymore, you throw the exception, which you diligently catch.
Contradictive, the method itself might very well throw an exception.
|
|
I have come across the following type of code many a times, and I wonder if this is a good practice (from Performance perspective) or not:
try { ... // some code } catch (Exception ex) { ... // Do something throw new CustomException(ex); }
Basically, ...
Started by Vaibhav on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The re-throw in your third example will throw an exception of the same type that was thrown by your "some code....
The re-throw in your second example will throw an exception of type Exception.
|