You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TerminalErrorNotification.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.application;
  17. import com.vaadin.tests.components.TestBase;
  18. import com.vaadin.ui.Button;
  19. import com.vaadin.ui.Notification;
  20. import com.vaadin.ui.UI;
  21. public class TerminalErrorNotification extends TestBase {
  22. @Override
  23. protected void setup() {
  24. Button button = new Button("Throw exception",
  25. event -> {
  26. throw new RuntimeException("You asked for it");
  27. });
  28. addComponent(button);
  29. }
  30. @Override
  31. public void error(com.vaadin.server.ErrorEvent event) {
  32. event.getThrowable().printStackTrace();
  33. UI mainWindow = getMainWindow();
  34. if (mainWindow != null) {
  35. Throwable throwable = event.getThrowable();
  36. // Find the root cause
  37. while (throwable.getCause() != null) {
  38. throwable = throwable.getCause();
  39. }
  40. Notification.show("Got an exception: " + throwable.getMessage(),
  41. Notification.TYPE_ERROR_MESSAGE);
  42. } else {
  43. System.out.println("No main window found");
  44. }
  45. }
  46. @Override
  47. protected String getDescription() {
  48. return "Showing a notification in the terminalError method should make the notification appear in the browser.";
  49. }
  50. @Override
  51. protected Integer getTicketNumber() {
  52. return Integer.valueOf(8778);
  53. }
  54. }