Jurjen Ladenius
Jurjen Ladenius

Reputation: 2085

Throwing custom exception from SSRS

Is it possible to throw a custom Exception from SSRS that I can catch in C#?

Something like:

try
{
    result = ssrs.Render(
        format,
        null,
        out extension,
        out encoding,
        out mimeType,
        out warnings,
        out streamIDs);
}
catch (CustomException ex)
{
    // do something
}
catch (Exception ex)
{

}

I'd use it to not display the report in the client's system. I'd prefer to keep business logic in the report.

Upvotes: 0

Views: 1197

Answers (2)

Jurjen Ladenius
Jurjen Ladenius

Reputation: 2085

We wanted to throw an exception to not generate a report based on data. We tried a custom DLL to raise an exception. Unfortunately that did not work either.

What we did is raise an error with a specific string from a stored procedure and parse the Exception message in C# that worked pretty well. Not as nice as we'd have like though.

Upvotes: 1

Steven V
Steven V

Reputation: 16595

Throwing a custom exception type that you implement inside your application? I don't think that's possible.

But, looking at the rendering code using a disassembler, it does look like it attempts to wrap many of the Reporting Services rendering/viewing exceptions using a base exception class ReportViewerException. You could attempt to catch that exception type and that should handle many of the rendering issues.

Granted, you can still get things like a ArguementOutOfRangeException, which would not be wrapped in a ReportViewerException. So you may want to take that into consideration as well.

Upvotes: 0

Related Questions