Properly Handling Exception Handling


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, when you say it like that, it is all so clear now Blink



But it is exactly right! Cool
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Thanks, Greg!

So, placing a throw after the rollback will force the handled exception to be an unhandled exception which will actually be handled by the program.cs unhandled exception handler?

Right?

Smooooth

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well said, Greg Wink
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Bill,



It is actually way easier than this. There is an application event handler in program.cs (appmain.vb) that is for unhandled exceptions. You'd put your SPXExceptionHandler.ReportException(ex); call in there and indicate through the event hards that you've handled it. Now any unhandled exception is handled by this code...every where.



Now in the case of using a try/catch, so you can do the rollback, you'd still want to handle that, but after you do the rollback, you'd rethrow the exception. You could even wrap the original exception in one specific to that situation.

private void cmdTransfers_Click(object sender, EventArgs e)

{

try

{

// Wrap this entire process in a transaction

BusinessLayer.TransactionBegin("MyDataSourceName", IsolationLevel.ReadCommitted);



// Retrieve the next [snip] . . . lots of stuff happening here . . .



MyLastProcedureToRun(myParm);



BusinessLayer.TransactionCommit("MyDataSourceName");

}

catch (Exception ex)

{

BusinessLayer.TransactionRollback("Dynamics");



// rethrow the original exception now that rollback is complete

Throw

}

}


Note that the procedure is only responsible for throwing the exception, not dealing with it...that is done in the application unhandled exception handler!



Hope that makes sense!
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Good morning,

I am working through some intricate code and I want to make sure I am made aware of any errors that may pop up at run-time.  How I have done this in the past is to create a class that I throw exceptions at and from there send emails or alerts to let me know what is going on.  As I understand it there is some exception handling that is already going on within the framework via an error provider.  How do I take advantage of that and still provide a streamlined way of handling my exceptions?  Also, is this a proper approach to using transactions within my code?

Here is an example of my code that I am trying to work this through:

private void cmdTransfers_Click(object sender, EventArgs e)
{
   
try
   
{
       
// Wrap this entire process in a transaction
       
BusinessLayer.TransactionBegin("MyDataSourceName", IsolationLevel.ReadCommitted);

       
// Retrieve the next [snip] . . . lots of stuff happening here . . .

      
MyLastProcedureToRun(myParm);

        BusinessLayer.TransactionCommit("MyDataSourceName");
    }
   
catch (Exception ex)
    {
       
// place cool SF exception handling here, if any

       
// this is my current way of doing it
       
SPXExceptionHandler.ReportException(ex);  // exceptions are logged, emailed, etc.
        BusinessLayer.TransactionRollback("Dynamics");
    }
}

Thanks!
Bill


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search