You should catch the exceptions properly, not with a MessageBox which tells you nothing about the exact exception thrown!
You should catch the exceptions properly, not with a MessageBox which tells you nothing about the exact exception thrown! At minimum your catch block should look like this: catch (Exception exc) { MessageBox. Show(exc.
Message); } and I say at minimum because you should in fact log the exception somewhere, using a logging framework like NLog or Log4Net and dump stack trace and other details. You are not even able to tell the excact type of Exception if you show a message with a static string and not the details of the actual exception.
This is general GDI error. ' Which seems the user is aware of the exception, just that a Generic GDI+ Error, is, well, awfully generic and the exception isn't in question here. – Mr. Disappointment Sep 12 at 11:25 what?
What does it mean? How was this explained in the question? – Davide Piras Sep 12 at 11:27 That's the point, this error can mean any number of things (invalid access rights, locked files, out of memory and so on.) The words 'improve this error' can be replaced with 'correct this error', I think.
– Mr. Disappointment Sep 12 at 11:29 @Mr. Disappointment instead of voting down everybody, consider that question was not reach of details and general GDI error as mentioned in the question could be anything, it is not said it's the exception type. My answer and other answers are suggesting ways to handle exceptions properly, better than in current code, not deserved down vote for assumptions on a question not well written. – Davide Piras Sep 12 at 11:29 No, if you have experience with GDI+ and someone tells you a general GDI error then that translates to a Generic GDI+ Error (that IS the error, in its entirety) , which is all the information you get.
They deserve down-votes because they don't properly answer the question, but go tangentially on about how to see the error, not fix it. – Mr. Disappointment Sep 12 at 11:31.
You should only catch specific exceptions that you intend to handle or recover from, and log the details. Never catch Exception as you would potentially be masking bigger issues with your server if they occur. Unexpected exceptions should bubble up so that the cause can quickly be identified when they occur.
See here for Best Practices for Handling Exceptions.
– TheCodeKing Sep 12 at 11:34 Yes, see my comments on other answers - this isn't the topic at hand and doesn't fix anything. – Mr. Disappointment Sep 12 at 11:36 Well we'll have to disagree on that, your obviously expecting a lot of GDI errors in your app. – TheCodeKing Sep 12 at 11:37 Really this should have been a comment as it doesn't directly address the issue.
– ChrisF Sep 12 at 11:56 The issue being? How to improve error handling? How can I improve this error?
– TheCodeKing Sep 12 at 12:10.
You're eating the exception and losing all the juicy detail. Try changing your catch block to something like this to see what's going on: catch (Exception ex) { MessageBox. Show(this, ex.ToString(), "Error Saving Image", MessageBoxIcons.
Error); } Also, consider implementing some logging (to the event viewer and/or text file. This will allow you to have a simple message box, but with all the juicy detail put somewhere useful to fetch after the event. Catch (Exception ex) { MessageBox.
Show(this, ex. Message, "Error Saving Image", MessageBoxIcon. Error); // _logger is a private field on this class in this case.
_logger. Log(ex, string. Format("Saving image to {0}", dialog.
Filename)) } You could look at Log4net amongst other things for the actual logging, but at the very least write a class to write exception detail to the event viewer.
This is general GDI error. ' Which seems the user is aware of the exception, just that a Generic GDI+ Error, is, well, awfully generic and the exception isn't in question here. – Mr. Disappointment Sep 12 at 11:26.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.