Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
AnswerRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
Luc Pattyn19-Nov-10 3:41
sitebuilderLuc Pattyn19-Nov-10 3:41 
AnswerRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
Manfred Rudolf Bihy19-Nov-10 3:42
professionalManfred Rudolf Bihy19-Nov-10 3:42 
GeneralRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
Kushagra Tiwari19-Nov-10 9:47
Kushagra Tiwari19-Nov-10 9:47 
AnswerRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
Ian Shlasko19-Nov-10 10:03
Ian Shlasko19-Nov-10 10:03 
AnswerRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
Kushagra Tiwari22-Nov-10 0:17
Kushagra Tiwari22-Nov-10 0:17 
GeneralRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
GuzmanJ2-Mar-11 10:37
GuzmanJ2-Mar-11 10:37 
AnswerRe: Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document Pin
gmr_evgen15-Aug-11 14:08
gmr_evgen15-Aug-11 14:08 
QuestionMoved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
#realJSOP19-Nov-10 1:40
professional#realJSOP19-Nov-10 1:40 
Is there a way to cut down on the individual exception handling code placed in classes and methods so it can be centralized but not result in termination.

I can see that you can use program.cs and put a try/catch around Application.Run. The exception can be caught. This provides a basis for logging and informing the user, but the application still terminates after the catch logic.

You can put an Application.Run in the catch and get it to start over one more time, but the next exception cannot be caught. So its not much use.

The solution I am trying to determine would look something like:

Form1.cs:

C#
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
    public partial class Form1 : Form    
    {        
        public Form1()        
        {
            InitializeComponent();        
        }

        private void testMethod()        
        {            
            throw new ArgumentException("Invalid parameter");        
        }              

        private void nextMethod()        
        {          
            // More Code        
        }
    }
}


Program.cs:

C#
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{    
    static class Program    
    {
        /// 
        /// The main entry point for the application.        ///
        [STAThread]        
        static void Main()        
        {
            try
            {
                Application.EnableVisualStyles();            
                Application.SetCompatibleTextRenderingDefault(false);            
                Application.Run(new Form1());         
            }
            catch
            {
                // Log Exception, Inform User.           
                // Return to Previous Level and continue.         
            }     
        }
    }
}


The return to previous level and continue does not seem possible. I am then left with sprinkling exception handling code throughout the application and replicating catch blocks to some degree.

It seems to me that there must be a way to create a centralized exception handler and reduce the number of try/catch blocks overall.

I have read quite a few articles but none seem to address this issue. I realize I can try to reduce the exception handling with logic and rethrow exceptiosn, etc. But this still leaves the issue open for me.

Am I missing something?

Any ideas welcome.

Thanks.

REMEMBER: THIS WAS ORIGINALLY POSTED IN Q/A BY SOMEONE ELSE, AND WAS MOVED HERE BECAUSE A THREADED DISCUSSION WAS MORE APPROPRIATE.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Luc Pattyn19-Nov-10 1:50
sitebuilderLuc Pattyn19-Nov-10 1:50 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 13:51
dpminusa20-Nov-10 13:51 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 14:54
dpminusa20-Nov-10 14:54 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Luc Pattyn20-Nov-10 16:02
sitebuilderLuc Pattyn20-Nov-10 16:02 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 20:06
dpminusa20-Nov-10 20:06 
AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Pete O'Hanlon19-Nov-10 2:34
mvePete O'Hanlon19-Nov-10 2:34 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 14:14
dpminusa20-Nov-10 14:14 
AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
_Erik_19-Nov-10 3:46
_Erik_19-Nov-10 3:46 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 14:18
dpminusa20-Nov-10 14:18 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
_Erik_20-Nov-10 16:01
_Erik_20-Nov-10 16:01 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa20-Nov-10 20:01
dpminusa20-Nov-10 20:01 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
_Erik_20-Nov-10 23:21
_Erik_20-Nov-10 23:21 
GeneralRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
dpminusa21-Nov-10 4:46
dpminusa21-Nov-10 4:46 
AnswerRe: Moved from Q/A (originally posted by dmpinusa): Centralizing Exception Handling Code Pin
Rhys Gravell21-Nov-10 23:57
professionalRhys Gravell21-Nov-10 23:57 
Questiondatetimepicker with multiple selected dates Pin
ajithnamboodiri18-Nov-10 19:58
ajithnamboodiri18-Nov-10 19:58 
AnswerRe: datetimepicker with multiple selected dates Pin
Mycroft Holmes18-Nov-10 20:46
professionalMycroft Holmes18-Nov-10 20:46 
AnswerRe: datetimepicker with multiple selected dates Pin
RobCroll19-Nov-10 0:55
RobCroll19-Nov-10 0:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.