Most browsers have an easily accessible history option where you can browse through and choose previously visited sites to open again. Not only are histories available, but some browsers including Safari have options for reopening the last closed window or even all the windows from the last session when the browser was run. In Safari these are available in the "History" menu.
Open the last closed window
This feature in Safari is exceptionally useful if you inadvertently close a window containing a page or pages you needed to view. Granted you can always go to the history list and browse for the site or sites you were visiting, but having a quick option is easiest.
This feature will open the window with all the tabs it contained; unfortunately it does not do this for individual tabs in a window, so if you close a tab without closing the full window, you will not be able to recover the tab with this option.
To tackle a closed tab, you can use the universal "Undo" option in Safari by choosing it from the Edit menu or by pressing Command-Z. This will relaunch the closed tab in the current Window, but its effects are limited to the window being open. Keep in mind that if you close the entire window containing one or more Web pages, then Command-Z will have no effect.
Open all windows from the last session
The last option for managing closed witndows in Safari is to reopen all the windows from the last time the program was run. Safari logs all currently loaded pages, their status as separate windows or tabs, and the window properties such as the location on screen and whether or not they are minimized. At any point in using Safari, you can invokde this option to re-open and restore all the windows from the previous session in addition to any new windows you may have opened.
This feature is exceptionally useful if you encounter a problem with Safari such as pages no longer loading properly, sudden slowdowns, or even crashes. In addition, many times changes to the program such as installing plugins will require the browser to be relaunched for changes to take effect. In these cases, it may be a pain to relaunch the program and then reopen all your windows manually after the program loads. Using the option to open all windows again can make this a lot less painful. The only problem is login sessions (for example, Webmail or social media sites) on Web pages may be reset.