1) Custom exceptions can help make your intentions clear.
How can this be? The intention is to handle or log the exception, regardless of whether the type is built-in or custom.
The main reason I use custom exceptions is to not use one exception type to cover the same problem in different contexts (eg parameter is null in system code w...
I have some code to update a database table that looks like
try
{
db.execute("BEGIN");
// Lots of DELETE and INSERT
db.execute("COMMIT");
}
catch (DBException&)
{
db.execute("ROLLBACK");
}
I'd like to wrap the transaction logic in an RAII class so I could just write
{
DBTransaction trans(db);
// Lots of DELETE ...
Constructor for PHP's exception has third parameter, documentation says:
$previous: The previous exception used for the exception chaining.
But I can't make it work. My code looks like this:
try
{
throw new Exception('Exception 1', 1001);
}
catch (Exception $ex)
{
throw new Exception('Exception 2', 1002, $ex);
}
I expect E...
Hello.
I was wondering if people would share their best practices / strategies on handling exceptions & errors. Now I'm not asking when to throw an exception ( it has been throroughly answered here: SO: When to throw an Exception) . And I'm not using this for my application flow - but there are legitimate exceptions that happen all the...
Hi,
My main application creates a new BackgroundWorker X
the DoWork event handler of X calls a method Y of my controller. This method creates the WebRequest (async.) instance and the callback using AsyncCallback.
When the response arrives the callback method Z gets called and the content will be analyzed. It can happen that the respons...
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive exception:
/// ...
/// <exception cref="FormatException">The file does not have a valid image format.</exception>
public static Image OpenImage( string filename )
{
try
{
return Image.FromFile( filename, );
}
catch( OutOfMe...
Hi,
I have a (rather large) application that I have written in C++ and until recently it has been running fine outside of visual studio from the release build. However, now, whenever I run it it says "Unhandled exception at 0x77cf205b in myprog.exe: 0xC0000005: Access violation writing location 0x45000200.", and leads me to "crtexe.c" at...
I have a multithreaded app that is very stable on all my test machines and seems to be stable for almost every one of my users (based on no complaints of crashes). The app crashes frequently for one user, though, who was kind enough to send crash reports. All the crash reports (~10 consecutive reports) look essentially identical:
Date...
/**
* An exception thrown when an illegal side pit was
* specified (i.e. not in the range 1-6) for a move
*/
public class IllegalSidePitNumException extends RuntimeException
{
/**
* Exception constructor.
* @param sidePitNum the illegal side pit that was selected.
*/
public IllegalSidePitNumException(int sideP...
Hello,
i have created a namedquery with ejb to check if the username is used.
When the singleResult is null, then i get the following Exception :
javax.persistence.NoResultException: getSingleResult() did not retrieve any entities
But this exception is the result that i want when the username is free.
Here is the code:
public Us...
I'm convinced at this point that I should be creating subclasses of std::exception for all my exception throwing needs. Now I'm looking at how to override the what method.
The situation that I'm facing, it would be really handy if the string what returns be dynamic. Some pieces of code parse an XML file for example, and adding a positio...
I saw some code like this:
try
{
db.store(mydata);
}
finally
{
db.cleanup();
}
I thought try is supposed to have a catch?
Why does this code do it this way?
...
public KalaGame(KeyBoardPlayer player1,KeyBoardPlayer player2)
{ //super(0);
int key=0;
try
{
do{
System.out.println("Enter the number of stones to play with: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
key = Integer.parseInt(br.readLine());
if(key<0 || key>10)
...
Hi,
I have a screen with a webView in my navigation controller stack and when I navigate from this view back to a previous before the page completely loaded I get a EXCEPTION_BAD_ACCESS. Seems, that the view with a webView being released before it comes to webViewDidFinishLoad function. My question is how to overcome this problem? I don...
I am considering a design where all fatal exceptions will be handled using a custom UncaughtExceptionHandler in a Swing application. This will include unanticipated RuntimeExceptions but also custom exceptions which are thrown when critical resources are unavailable or otherwise fail (e.g. a settings file not found, or a server communic...
Trying to connect to an imap server from an app that uses javamail to connect. I can't modify the code, but it's throwing the 'Server chose unsupported or disabled protocol: SSLv3' error, and I can't find a property that I can override to enable that protocol. The server I'm connecting to does not support TLSv1 (yes, it's old).
...
hi.
my project uses 2 different C++ compilers, g++ and nvcc (cuda compiler).
I have noticed exception thrown from nvcc object files are not caught in g++ object files.
are C++ exceptions supposed to be binary compatible in the same machine?
what can cause such behavior?
try { kernel_= new cuda:: Kernel(); }
catch (...) { kernel_= NULL...
Hello,
I'm investigating a bit about how the unhandled exceptions are managed in .Net and I'm getting unexpected results that I would like to share with you to see what do you think about.
The first one is pretty simple to see. I wrote this code to do the test, just a button that throws an Exception on the same thread that created the ...
I don't do a lot of Windows GUI programming, so this may all be common knowledge to people more familiar with WinForms than I am. Unfortunately I have not been able to find any resources to explain the issue, I encountered today during debugging.
If we call EndInvoke on an async delegate. We will get any exception thrown during executi...
We're having problems with Windows silently eating exceptions and allowing the application to continue running, when the exception is thrown inside the message pump. For example, we created a test MFC MDI application, and overrode OnDraw:
void CTestView::OnDraw(CDC* /*pDC*/)
{
*(int*)0 = 0; // Crash
CTestDoc* pDoc = GetDocument...