I used to create interfaces with IEnumerable<T> as return type, whenever I want to specify that a particular output is read-only. I like it as it's minimalistic, hides implementation details and decouples a callee from a caller.
But recently a colleague of mine argued that IEnumerable<T> should be kept for scenarios which involve lazy e...
When i use dlopen to dynamically load a library it seems i can not catch exceptions thrown by that library. As i understand it it's because dlopen is a C function.
Is there another way to dynamically load a library that makes it possible to catch exceptions thrown by the lib in GCC?
In Windows you can use LoadLibrary but for Linux i ha...
Which exception should be thrown here?
public static string DoStuff(this Control control)
{
if (control == null)
{
throw new ArgumentNullException();
}
// Code goes here...
}
I thought about the following:
ArgumentNullException (as used below)
InvalidOperationException
NullReferenceException
My choice wou...
I read a lot about how bad catching base Exceptions is and I have to confess that I did it also:
try{
...
}
catch (Exception exception){
MessageBox.Show(exception.Message, "Error!");
MyLogger.Log(exception.Message);
}
Now I would like to do it right and have some questions about it:
Which exceptions should I catch (for e...
I'm implementing the Enterprise Library Exception Handling Application Block in an ASP.NET application that I am building. I'm planning to handle uncaught application exceptions by placing the following code in my Global.asax.cs:
protected void Application_Error()
{
Exception error = Server.GetLastError();
Exception ...
I want to catch and ignore and ArrayIndexOutOfBoundsException error (basically it's not something I have control over, so I need my program to keep chugging along).
However my try/catch pair doesn't seem to catch the exception and ignore it. Hopefully you can pick out what I am doing wrong.
The exception occurs at this line
content...
I would like to automagically add the following code around the body of some methods:
try
{
// method body
}
catch (Exception e)
{
throw new MyException("Some appropriate message", e);
}
I am working with PostSharp 1.0 and this is what I've done at the moment:
public override void OnException(MethodExecutionEventArgs eventArgs)...
if i made my exception Serializable like this article from msdn , so can my exception serialized over WCF ?
...
Hello Guys,
I would like to know if there are any recommended patterns for errorKey -> errorMessage look up? I am trying to improve my exception handling techniques and would be grateful for some ideas.
I am using some third party software and when an exception occurs they return an error key in the format THIRD_PARTY_ERROR_KEY. This...
I've got some code in my web app to deal with unhandled exceptions - it hands off to a fancy custom error page which logs the details. But what if there's an unhandled exception within the custom error page?
I can detect this condition in my general exception handler by checking to see if Request.CurrentExecutionFilePath equals my custo...
when an exception occurs that a method is unable to handle - does the program terminate and show the error number ? where does the error number and information about the error come from ? should the programmer while coding have an idea what kind of exception might occur. if so why does'nt he ensure that exception does not occur .
...
Is there any way in C# to easily achieve the following pseduo-code:
try
{
...
}
catch ( ExceptionTypeA, ExceptionTypeB, ExceptionTypeC as ex)
{
... same code for all threw
}
Or
try
{
...
}
catch ( ExceptionTypeA ex )
catch ( ExceptionTypeB ex )
catch ( ExceptionTypeC ex )
{
... same code for all exceptions of A, B or C
}
I guess wh...
( patience requested as i'm new to programming )
when you add the phrase throws ABCexception in method declaration like this
public static void main(String[] args) throws ABCException {
}
does it mean that the you expect the method could generate an ABC exception and by writing throws ABCException ... when this exception occurs .. ...
If i have an interface, which i add comments to to identify that a specific exception will be thrown, is it ok for implementing classes to throw different exceptions?
A (bad) example is:
public interface IWidgetWorker {
/// <summary>
/// Do the work required for the specified work id.
/// </summary>
/// <param name="wor...
Sometimes (about 1 out of 100 runs), my program terminates with this message:
terminate called after throwing an instance of 'Poco::SystemException'
what(): System exception
my code is not the one catching the exception (all my catches are more verbose), and I am not sure where it's caught.
it's very likely that the exception does ...
If I want to log all occournace of exception through out my application so far,
should I inherit Exception class and throw all exception of that class,
whose constructor will log the error details..
or any idea or suggestion???
...
I making report engine with JasperReport. Everything works fine so far but I have small miss understanding. In my code I'm trying to compile template file and return JasperReport object and if the compilation is failed then compile another file and return error message. But it does not work for some reason. Here is my code:
/**
* Gener...
So I've got a WCF client consuming an ASMX web-service. Everything works fine, except exception handling.
Where I should get a (non-contractual) FaultException, i get the CommunicationException.
What may be wrong?
Here goes the relevant data:
SOAP response (seems to be according to specification):
<?xml version="1.0" encoding="utf...
I know that this type of question has been asked over and over again, however, I have yet to find a definitive answer for the problem I am looking into.
From all the content on exception handling that I have read it appears that the general concensus is that exceptions should only be used for exceptional circumstances. I've also read i...
class MyController {
def myAction = {
throw new MyException("Test")
}
}
Is it possible to catch / handle the exception thrown by the code above? The following url-mapping kinda works, but it causes the exception to be logged, which is annoying because in my case I'm able to handle it.
"500"(controller: "error", action: 'm...