function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
paul-lmipaul-lmi 

question on test coverage and error handling

i'm trying to figure out how i force an exception to happen so I can cover my catch statements in testMethods.

can anyone tell me how to force a DML exception and a generic one?  i can't figure out how, and when i try to manually set one up, apex just tells me that the exceptions cannot be constructed.
HL-DevHL-Dev
This should get you an DML Exception.
- Create a new object (Task for example) and try to assign it to a user (OwnerId) that doesn't exist in your environment.
- Insert or update the object.
 
Also, if you're trying to force a System.QueryException, you could construct a SELECT query that doesn't return any rows.