You searched for exceptions. We found 168 results in 0.145 seconds.

How to OR when capturing multiple webdriver exceptions

I am trying to capture multiple exceptions like this but I get error '); expected'. How do I do it using ||? try { //find an element here }catch(...
Jon Skeet
people
quotationmark

Assuming you're using Java 7, you should be able to use this syntax: catch (StaleElementReferenceException | NoSuchElementException e) Note the single |, as well as the single variable name. See the "Catching Multiple Exception Types... more

people

Is this pattern for handling IO exceptions in Java correct?

In the following code snippet, if ex1 is thrown, will be be caught by the second catch block, or will it be thrown back to the caller of the method? And if it is thrown back to...
Jon Skeet
people
quotationmark

Both of those exceptions would be thrown back to the caller... although a single exception in any particular situation. If the body of the outer try block throws and then close throws as well, only the second exception would be seen by the... more

people

Unobserved task exceptions in .NET4

According to some articles and blogs a code like the following one should lead to an exception in .NET 4 static void Main(string[] args) { Task.Factory.StartNew(()...
Jon Skeet
people
quotationmark

My guess is that you're actually running on .NET 4.5. Bear in mind that .NET 4.5 is effectively installed over the top of .NET 4. Even if your application is targeted at .NET 4, if the user has installed .NET 4.5 you'll get the new... more

people

Tasks & Exceptions Issue

I am new to tasks and I hope you can help me out with this. Here is code: Task tast = null; try { tast = new Task(() => { ... }); tast.Start(); if (tast...
Jon Skeet
people
quotationmark

You're calling Task.Wait() - which will throw an exception if the task is faulted. If you don't call Task.Wait(), you won't get the exception in your thread... but of course you won't spot when it's finished, either. There are various ways... more

people

method to call other methods and handle exceptions

Background: I wrote a C# application that is calling multiple methods from a web service. Methods are being called from loops in Main, from some classes, and so on. Each of these...
Jon Skeet
people
quotationmark

It sounds like you probably want something like this: private T CallWithRetries<T>(Func<T> call) { // TODO: Work out number of retries, etc. for (int i = 0; i < 3; i++) { try { return... more

people

Convert string to ASCII without exceptions (like TryParse)

I am implementing a TryParse() method for an ASCII string class. The method takes a string and converts it to a C-style string (i.e. a null-terminated ASCII string). I had been...
Jon Skeet
people
quotationmark

Two options: You could just ignore Encoding entirely, and write the loop yourself: public static bool TryParse(string s, out byte[] result) { result = null; // TODO: It's not clear why you don't want to be able to convert an... more

people

How to handle unhandled exceptions in Task awaiter

I am having problems with unhandled exceptions being thrown in the task awaiter. These exceptions are just ignored and never propagated anywhere. Code example: Task<bool>...
Jon Skeet
people
quotationmark

The Task<bool> returned from your Test method will become faulted. If you await that task (or call Wait() on it) then the exception will be rethrown at that point. If you choose to ignore the faulted state of the task, then yes,... more

people

How to tell JUnit to ignore nested exceptions?

If I have 2 classes as such: public class A { public A(boolean bool){ if(bool){ // currently broken // would throw RuntimeException ...
Jon Skeet
people
quotationmark

No - the result of calling the method is a RuntimeException, and that's what you're testing. How is JUnit meant to tell the difference between a RuntimeException from the exact method you're calling, and one from a dependent call? One of... more

people

Why is the bitwise OR operator ( | ) used when catching multiple exceptions in Java?

I've just learned that | is used to catch multiple exceptions in the same block; | is the bitwise operator for OR. In this case, is it still used as a bitwise operator or does it...
Jon Skeet
people
quotationmark

In this case, is it still used as a bitwise operator or does it have a different meaning when in context? It has a different meaning - although it's of the same "flavour" in that it's "if exception X is caught, or exception Y is... more

people

Where do Java exceptions came from?

Until now, I thought that every Java exception has to be created somewhere by a constructor, as I can create on my own, custom exceptions: throw new Exception(); But now it...
Jon Skeet
people
quotationmark

The exception being declared isn't about what that implementation can throw - it's about what that implementation or the implementation in subclasses can throw. Service is an abstract class - and so are the two direct subclasses... more

people