Exception Handling

If there is a situation where you need to catch an exception in order to gracefully cleanup or perform some additional task but you still want the underlying exception to be logged, you can use the LogException( Exception exception ) method that is on the base RockBlock:

// Your code...
try
{
    // ...is doing something important for the Kindgom...
}
catch ( Exception ex )
{
    // ...but something went wrong that needs to be logged.
    LogException( ex );
    
    // Now you can try to gracefully continue if possible
}

Just keep in mind that catching and logging exceptions is not free. There is always a small performance penalty when handling exceptions unnecessarily. So use your best judgement when this is needed. If the exception is not actionable, you might consider not logging it.

Just Logging

If you don't have an exception but just need to log something, you can use Rock's Logging Engine.

Last updated