For a week I've now started using Ubuntu on my laptop as my main OS for work. Sometimes my laptop battery is finished, so it get's powered off. I'm not sure whether it does so in a somewhat graceful way, or that the power is simply cut.
When this happens, and I start it again after reconnecting the power it starts up afresh, without anything open. Is there a possibility to auto reopen all programs that I had open?
save session
in gnome3 using dconf Editor and navigating to org.gnome.gnome-session should give you an option to auto-save sessions
Since that doesn't seem to work for a lot of users, you can also hibernate if your battery is low.
hibernate
There is a great How To from Ubuntu that should get you started, applicable to both Wayland and Gnome.
If that doesn't work there is this great answer for an alternative solution for Gnome.
You don't mention your Ubuntu version or your Desktop Environment.
I'm using Ubuntu 16.04 LTS with Unity Desktop.
When the battery starts running low, warning messages (via pop-up bubbles) start appearing. This is designed to give you time to start saving your work and gracefully power down your system.
The other answer references Gnome and if you are on Ubuntu 17.10 you may be using Wayland which may not give you the same warning messages.
In either case this Ask Ubuntu Q&A How to change critically low battery value? should prove helpful. One answer in particular states:
I hope this helps!