Magento throw, \Magento\Framework\Exception\AlreadyExistsException
error type when we have we have tried to a new account on an existing email address.
$result = $connection->fetchOne($select, $bind);
if ($result) {
throw new AlreadyExistsException(
__('A customer with the same email already exists in an associated website.')
);
}
So, on Controller, you can handler by this type of code
try{
......
}catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
$message = $this->__('There is already an account with this emails address. If you are sure that it is your email address, <a href="%s">click here</a> to get the password and access your account.', $url);
$this->_getSession()->addError($message);
}catch(\Magento\Framework\Exception\LocalizedException $e){
$message = $e->getMessage();
$this->_getSession()->addError($message);
}catch (\Exception $e) {
$message = $e->getMessage();
$this->_getSession()->addError($message);
}
BEIEF:
Magento2 have used little bit different type of exception handling for creating thrown exception and check the exception type.
Before the understand how to define the exception and what type of exception, Magento use then you have to check Magento in -build exception type