In OOP this is usually done via exceptions