Provide relevant code examples, with code comments based on this case study of how to implement the following:

1. %TYPE attribute;
2. %ROWTYPE attribute
3. System defined exception.
4. User defined exception