SSIS Script Task is throwing an exception, how to view the message? - debugging

SSIS is showing some useless "Target of invocation has thrown an error" along with an equally useless stack trace that shows only the invocation call. Logging is enabled.
Is there a way to view the actual exception message thrown by the package without attaching some debugger?

Just trap the exception in a try..catch statement and use the FireError method in the catch block:
public void Main()
{
...
try
{
...
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.Events.FireError(0, "ERROR", ex.Message, null, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}

Related

How can I handle async task cancel when I'm calling it from while condition?

I have a loop like this inside a try-catch block:
try
{
while ((receivedBytesCount = await tcpClient.GetStream().ReadAsync(rxBytes, 0, rxBytes.Length, tcpCancellationSource.Token)) != 0)
{
// handling rxBytes[]
}
}
catch (OperationCanceledException oce)
{
Console.WriteLine($"Shutting down TCP thread...");
}
catch (Exception e)
{
// handle other exceptions
}
When I request cancel on tcpCancellationSource from somewhere:
tcpCancellationSource.Cancel();
my application throws OperationCanceledException exception, but not from try-catch block.
How should I handle that cancellation properly?

Expecting to catch an Aggregate Exception

I am trying to understand exception handling in TPL Dataflow so I can effectively handle errors. In my comment numbered 1. below I am expecting to catch an AggregateException but everything just halts and doesn't recover. If I remove the throw (2.) then the ActionBlock continues to process but again, the AggregateException handler doesn't trigger.
Would anyone be able to help with an explanation to improve my intuition.
Would also welcome any documentation references on the topic.
async Task Main()
{
var ab = new System.Threading.Tasks.Dataflow.ActionBlock<int>(async a => {
try
{
await Task.Delay(100);
if (a == 7)
{
throw new Exception("Failed");
}
else
{
Console.WriteLine(a);
}
}
catch (Exception ie)
{
Console.WriteLine(ie.Message);
throw; //2. This causes the actionblock to halt, removing allows block to continue
}
});
for (int i = 0; i < 10; i++)
{
await ab.SendAsync(i);
}
ab.Complete();
try
{
await ab.Completion;
}
catch (AggregateException ae)
{
Console.WriteLine(ae.Flatten().Message);
// 1. Expecting to catch here.
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
What you're seeing is the await unwrapping your Aggregate Exception. When you await the completion task the exception is unwrapped and thrown to the general exception catch. But if you don't unwrap the exception then you'd see the exception caught as an aggregate exception like this:
try
{
ab.Completion.Wait();
}
catch (AggregateException ae)
{
Console.WriteLine("Aggregate Exception");
// 1. Expecting to catch here.
}
catch (Exception e)
{
Console.WriteLine("Exception Caught");
}
It's obviously better to properly await the completion but this samples shows you that indeed an AggregateExcpetion is caught when it's not unwrapped.

Cannot catch NoSuchElementException with Selenide

I’m trying to catch NoSuchElementException. This is my code:
public void checkActiveApps() {
try {
$(BUTTON).click();
} catch (org.openqa.selenium.NoSuchElementException e) {
System.out.println(e);
}
}
But the exception is still thrown. How to catch it?
This is the log:
Element not found {button[role='checkbox']}
Expected: visible
Screenshot: file:/Users/user/source/project/build/reports/tests/1537866631954.0.png
Page source: file:/Users/user/source/project/build/reports/tests/1537866631954.0.html
Timeout: 4 s.
Caused by: NoSuchElementException: Unable to locate element: button[role='checkbox']
at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:31)
at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:82)
at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:59)
at com.codeborne.selenide.impl.WebElementSource.findAndAssertElementIsVisible(WebElementSource.java:72)
at com.codeborne.selenide.commands.Click.execute(Click.java:16)
at com.codeborne.selenide.commands.Click.execute(Click.java:12)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)
at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:90)
at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)
I use selenide version 4.12.3
Selenide does not throw Selenium exceptions as it uses it's own.
You can try using:
public void checkActiveApps() {
try {
$(BUTTON).click();
} catch (com.codeborne.selenide.ex.ElementNotFound e) {
System.out.println(e);
}
}
Why do you want to catch it anyway?

system.threading .threadAbortException error

I am taking over an existing website and I am trying to get the application running on my machine, however I can't launch the application because I get the following error.
System.Threading.ThreadAbortException occurred
HResult=0x80131530
Message=Thread was being aborted.
Source=mscorlib
StackTrace:
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
This is my code
protected void Application_BeginRequest(object sender, EventArgs e) {
if (DemoWeb.Helpers.Application.ApplicationManager.StartUpError != "")
{
Response.Write("<div class=\"demoweb-securityerror\">" + demoweb.Helpers.Application.ApplicationManager.StartUpError + "</div>");
Response.End();
}
How can I get it to bypass the response.end?
I got it to work.
I just added a try and catch method and moved the Response.End
try {
// code
}
catch(exception ex)
{
Response.End();
}

Exception while Disposing Camera before initialization is ready

I use a code from http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202956%28v=vs.105%29.aspx
while
I've got exception when i push back button but camera is not Initialized.
An exception of type 'System.ObjectDisposedException' occurred in Microsoft.Devices.Camera.ni.dll and wasn't handled before a managed/native boundary
How to avoid exception?
The problem with:
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
try
{
if (_photoCamera != null )
{
// Dispose camera to minimize power consumption and to expedite shutdown.
_photoCamera.Dispose();
_photoCamera.Initialized -= cam_Initialized;
_photoCamera.AutoFocusCompleted -= _photoCamera_AutoFocusCompleted;
}
}
catch (Exception)
{
throw;
}
}

Resources