59
59
import org .openqa .selenium .Platform ;
60
60
import org .openqa .selenium .Point ;
61
61
import org .openqa .selenium .SearchContext ;
62
+ import org .openqa .selenium .SessionNotCreatedException ;
62
63
import org .openqa .selenium .TakesScreenshot ;
63
64
import org .openqa .selenium .WebDriver ;
64
65
import org .openqa .selenium .WebDriverException ;
@@ -498,7 +499,7 @@ protected Response execute(CommandPayload payload) {
498
499
long start = System .currentTimeMillis ();
499
500
String currentName = Thread .currentThread ().getName ();
500
501
Thread .currentThread ().setName (
501
- String .format ("Forwarding %s on session %s to remote" , command .getName (), sessionId ));
502
+ String .format ("Forwarding %s on session %s to remote" , command .getName (), sessionId ));
502
503
try {
503
504
log (sessionId , command .getName (), command , When .BEFORE );
504
505
response = executor .execute (command );
@@ -518,22 +519,24 @@ protected Response execute(CommandPayload payload) {
518
519
} catch (WebDriverException e ) {
519
520
e .addInfo ("Command" , command .toString ());
520
521
throw e ;
521
- } catch (Exception e ) {
522
+ } catch (Throwable e ) {
522
523
log (sessionId , command .getName (), command , When .EXCEPTION );
523
- String errorMessage = "Error communicating with the remote browser. " +
524
- "It may have died." ;
525
524
if (command .getName ().equals (DriverCommand .NEW_SESSION )) {
526
- errorMessage = "Could not start a new session. Possible causes are " +
527
- "invalid address of the remote server or browser start-up failure." ;
528
- }
529
- UnreachableBrowserException ube = new UnreachableBrowserException (errorMessage , e );
530
- if (getSessionId () != null ) {
531
- ube .addInfo (WebDriverException .SESSION_ID , getSessionId ().toString ());
532
- }
533
- if (getCapabilities () != null ) {
534
- ube .addInfo ("Capabilities" , getCapabilities ().toString ());
525
+ throw new SessionNotCreatedException (
526
+ "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." ,
527
+ e );
528
+ } else {
529
+ WebDriverException toThrow = new UnreachableBrowserException (
530
+ "Error communicating with the remote browser. It may have died." ,
531
+ e );
532
+ if (getSessionId () != null ) {
533
+ toThrow .addInfo (WebDriverException .SESSION_ID , getSessionId ().toString ());
534
+ }
535
+ if (getCapabilities () != null ) {
536
+ toThrow .addInfo ("Capabilities" , getCapabilities ().toString ());
537
+ }
538
+ throw toThrow ;
535
539
}
536
- throw ube ;
537
540
} finally {
538
541
Thread .currentThread ().setName (currentName );
539
542
}
0 commit comments