Add exception log

hello community . I created new doctype to save some exceptions happening in other doctype . for example , I have some conditions to edit a doctype . if not fulfilled an exception will occur . but I want to save the attempt in other doctype . everything works fine but the log creation is happening before the exception so when the exception appear it will cancel that saved doctype . writing it after the exception obviously won’t fix the problem . and I can’t remove the exception because I need it to stop the action . any help ?