Try this quick and simple way to find out the domain name that you are currently connected:
The domain name is returned if you are currently connected to a domain. Otherwise, you will receive an exception. You can also return arbitrary messages when not connected to a domain by adding an error handler: