system.threading .threadAbortException error - threadabortexception

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();
}

Related

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?

Debugger always Break when invoke GetFileAsync in windows 8 store apps (metro style)

This problem confuse me several days, when the code run to
await ApplicationData.Current.LocalFolder.GetFileAsync(udFileName);
The app was always jump to
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
The Exception e is:
{Windows.UI.Xaml.UnhandledExceptionEventArgs}
Exception {"Object reference not set to an instance of an object."}
System.Exception {System.NullReferenceException}
Message "System.NullReferenceException.......
Following is the function I invoked:
public async void RestoreUserDefaults()
{
string udFileName = "userdefaults.udef";
bool bExist = true;
{
try
{
await ApplicationData.Current.LocalFolder.GetFileAsync(udFileName);
}
catch (FileNotFoundException)
{
bExist = false;
}
}
}
I had add the file type to the package.appxmanifest.
anyone can help me, so many thanks.....

Windows Service not starting chrome with Process.Start()

I have written a windows service that is supposed to run a chrome instance.
how ever on attaching the service to the process I am able to hit the breakpoint to Process.Start but it does not opens the chrome.
also I do not get any error.
can anyone help me here.
protected override void OnStart(string[] args)
{
var timer = new Timer(5000);
timer.Elapsed += TimerElapsed;
timer.Start();
}
void TimerElapsed(object sender, ElapsedEventArgs e)
{
try
{
var processes = Process.GetProcessesByName("Chrome");
var found = false;
foreach (var process in processes)
{
if (process.MainWindowTitle.StartsWith("title"))
{
found = true;
}
}
if (!found)
{
var process = Process.Start("Chrome", "http://localhost");
}
}
catch (Exception ex)
{
}
}
If I create a windows application for the same then it works fine.
due to session 0 isolation I guess this is not a good idea to proceed upon..
Click here to know more

Double download with WebClient.OpenReadAsync

Ok, in my app I need to download two lists of datas to elaborate them but I can't realize how to do it..
I click a button and then I think the downloads start almost together. This is good for me, what it's not good is that my application can't understand how to wait the downloads before doing anything else..
I know there's a design problem but I cannot figure out how to resolve it..
The code is something (more or less) like this:
private void button_Click(object sender, RoutedEventArgs e)
{
try
{
WebClient webClient = new WebClient();
Uri uri = new Uri("http://myRESTservice");
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(uri); //this will set a private variableA
dwnl();
doSomething(); //this will do something with A and B
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dwnl()
{
try
{
WebClient webClient = new WebClient();
Uri uri = new Uri("http://myRESTservice/anotherAddress");
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted_B);
webClient.OpenReadAsync(uri); //this will set a private variableB
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Hope you understand the problem..
While your application is downloading the data, i.e. the OpenReadAsync method has been called you could show a busy indication. Your doSomething method would then be called from within your OpenReadCompleted event handler.
If you want one download to occur after the other has completed then you could also call the dwnl method from within your OpenReadCompleted event handler.

Resources