As far as I have understood, dependency injection separates the application wiring logic from the business logic. Additionally, I try to adhere to the law of Demeter by only injecting direct collaborators.
If I understand this article correctly, proper dependency injection means that collaborators should be fully initialized when they a...
The below code is a factory class that is delivers objects of type IGraph that have the GraphTypeAttribute implemented. Inside the static constructor of the GraphFactory, a list is built by using Linq to collect the appropriate classes to be delivered by the Factory. Normally without Linq I had a buch of loops and if-then's that could be...
No content available!
...
I want to check if the server is not accessible and if its not accessible i want to print a friendly message on my login page. Like when user input its credential and in exception i got
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible....
I had a function that returned a random member of several groups in order of preference. It went something like this:
def get_random_foo_or_bar():
"I'd rather have a foo than a bar."
if there_are_foos():
return get_random_foo()
if there_are_bars():
return get_random_bar()
raise IndexError, "No foos, no...
Hi
I have a WCF service that is called by a Windows Mobile application running on a PDA. I've set up the server code to send WCF faults if there is a problem. This is the code that I think I am supposed to be using on the client:
try
{
var data = myService.GetSomeData();
}
catch (FaultException<Service.CustomFault> fault)
{
mes...
This is a C# Winforms App in .NET 4.0.
I receive a byte array from a web server which is supposed to be a JPG image. I convert this array to an image as follows:
// byte[] ImageData ...
bool ValidImage = false;
try
{
MemoryStream ms = new MemoryStream(ImageData);
Bitmap FinalImage = new Bitmap(ms);
ValidImage = true;
}
catc...
what does it mean when one says allow exception to propagate upwards to the client ??
How does it work?
...
In Javascript, suppose I want to perform some cleanup when an exception happens, but let the exception continue to propagate up the stack, eg:
try {
enterAwesomeMode();
doRiskyStuff(); // might throw an exception
} catch (e) {
leaveAwesomeMode();
throw e;
}
doMoreStuff();
leaveAwesomeMode();
The problem with this code is that ...
Why do I not see the MessageBox with exception details when I run my program by executing exe fine in bin debug folder?
I do see the exception when I debug (run) the program from Visual Studio.
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(...
In some libraries it is common practice to make custom Exception classes for every error condition, like:
class FileNotFound_Exception extends Exception {}
You can handle certain type of Exception, however you cannot read all source code of all libraries to remember each Exception class, and cannot take full advantage of using custom ...
I use rescue for everything, not just for "rescuing" exceptions. I mean, I just love the way it spares me verification and double checking data.
By example, lets say I have a model Item what may or may not have a User. Then, when I want to get the owner's name of the item I write:
item.user.name rescue ""
instead of something like
i...
How can i gets the name of all SQL exceptions? For handling them in my project? Thanks.
...
Joshua Bloch in his Effective Java writes :
"Use the Javadoc @throws tag to document each unchecked exception that
a method can throw, but do not use the throws keyword to include unchecked
exceptions in the method declaration. "
Well that sounds reasonable indeed, but how to find out, what unchecked exception can my method throw?
Let...
1)
1 - Only handle exceptions that you
can actually do something about, and
2 - You can't do anything about the vast majority of exceptions
a) I assume that “By not handling an exception” the text is suggesting that we should let the exception bubble up the stack, where runtime will abort our application?!
b) But why is lett...
I have been working on this program for quite sometime and my brain is fried. I could use some help from someone looking in.
I'm trying to make a program that reads a text file line by line and each line is made into an ArrayList so I can access each token. What am I doing wrong?
import java.util.*;
import java.util.ArrayList;
import ...
I am using a Datasource to log my audit information per user-request.
The bean is defined in a springContext.xml sourced during initialization.
Whenever the DB is down, the bean initialization fails with following error: DataAccessException.
What I want to do is continue after this exception(since it is ok not to be able to log).
How d...
I have the following function that was written by someone else, however I am rewriting this application and I was just wondering if there isn't any better way to do exception handling, besides just returning what was originally passed to the function?
CComVariant GetFldVar(ADO_RsPtr rs, long nIndex, CComVariant def)
{
try
{
...
Hi all,
When I have a method that calls a set of methods that offer strong guarantee, I often have a problem on rolling back changes in order to also have a strong guarantee method too. Let's use an example:
// Would like this to offer strong guarantee
void MacroMethod() throw(...)
{
int i = 0;
try
{
for(i = 0; i < 100; ++i)
...
1) If we handle an exception inside page-level handler ( Page_Error ), then this page-level handler returns you back to the requested page, which is empty, since instances of control are not created.
a) What’s the logic behind runtime not rendering any of the page's controls if exception is handled by Page_Error?
b) So the only differ...